Example usage for weka.classifiers.lazy IBk setDistanceWeighting

List of usage examples for weka.classifiers.lazy IBk setDistanceWeighting

Introduction

In this page you can find the example usage for weka.classifiers.lazy IBk setDistanceWeighting.

Prototype

public void setDistanceWeighting(SelectedTag newMethod) 

Source Link

Document

Sets the distance weighting method used.

Usage

From source file:jjj.asap.sas.models1.job.BuildCosineModels.java

License:Open Source License

@Override
protected void run() throws Exception {

    // validate args
    if (!Bucket.isBucket("datasets", inputBucket)) {
        throw new FileNotFoundException(inputBucket);
    }/*from   w  w  w .jav  a2 s .  co  m*/
    if (!Bucket.isBucket("models", outputBucket)) {
        throw new FileNotFoundException(outputBucket);
    }

    // init multi-threading
    Job.startService();
    final Queue<Future<Object>> queue = new LinkedList<Future<Object>>();

    // get the input from the bucket
    List<String> names = Bucket.getBucketItems("datasets", this.inputBucket);
    for (String dsn : names) {

        int essaySet = Contest.getEssaySet(dsn);

        int k = -1;
        switch (essaySet) {

        case 3:
            k = 13;
            break;
        case 5:
        case 7:
            k = 55;
            break;
        case 2:
        case 6:
        case 10:
            k = 21;
            break;
        case 1:
        case 4:
        case 8:
        case 9:
            k = 34;
            break;
        }

        if (k == -1) {
            throw new IllegalArgumentException("not k defined for " + essaySet);
        }

        LinearNNSearch search = new LinearNNSearch();
        search.setDistanceFunction(new CosineDistance());
        search.setSkipIdentical(false);

        IBk knn = new IBk();
        knn.setKNN(k);
        knn.setDistanceWeighting(INVERSE);
        knn.setNearestNeighbourSearchAlgorithm(search);

        queue.add(Job.submit(new ModelBuilder(dsn, "KNN-" + k, knn, this.outputBucket)));
    }

    // wait on complete
    Progress progress = new Progress(queue.size(), this.getClass().getSimpleName());
    while (!queue.isEmpty()) {
        try {
            queue.remove().get();
        } catch (Exception e) {
            Job.log("ERROR", e.toString());
            e.printStackTrace(System.err);
        }
        progress.tick();
    }
    progress.done();
    Job.stopService();

}