diva.sketch.classification
Class KNNClassifier

java.lang.Object
  extended by diva.sketch.classification.KNNClassifier
All Implemented Interfaces:
Classifier, TrainableClassifier

public class KNNClassifier
extends Object
implements TrainableClassifier

A K Nearest Neighbor classifier compares a given example (feature set) to the training set and make its prediction based on the majority match in the top K candidates.

Version:
$Revision: 1.2 $
Author:
Heloise Hse (hwawen@eecs.berkeley.edu)

Field Summary
static double[] f1
           
static double[] f2
           
static double[] f3
           
static double[] f4
           
static double[] f5
           
static double[] f6
           
static double[] f7
           
static double[] f8
           
static double[] f9
           
 
Constructor Summary
KNNClassifier()
           
KNNClassifier(int k)
          Create a K nearest neighbor classifier in which K is set to specified number.
 
Method Summary
 Classification classify(FeatureSet s)
          Compare the given example (features) to the examples in the training set and save the top K closest matches in ascending distance values.
 void clear()
          Clear all results of previous trainings (presumably so that this classifier can be trained again from scratch).
 boolean isIncremental()
          Return true.
static void main(String[] argv)
           
 void setK(int k)
          Set the value of K.
 void train(TrainingSet s)
          Store the given training set which will be used during classification.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

f1

public static double[] f1

f2

public static double[] f2

f3

public static double[] f3

f4

public static double[] f4

f5

public static double[] f5

f6

public static double[] f6

f7

public static double[] f7

f8

public static double[] f8

f9

public static double[] f9
Constructor Detail

KNNClassifier

public KNNClassifier()

KNNClassifier

public KNNClassifier(int k)
Create a K nearest neighbor classifier in which K is set to specified number.

Method Detail

setK

public void setK(int k)
Set the value of K. The classifier finds the closest K matches.


train

public void train(TrainingSet s)
           throws ClassifierException
Store the given training set which will be used during classification. If a training set already exist, this method simply adds the example in the given training set (s) to the existing set. This also means that if an example in "s" already exists in the current training set, it'll be added again.

Specified by:
train in interface TrainableClassifier
Throws:
ClassifierException

isIncremental

public boolean isIncremental()
Return true. This classifier is incremental. It supports multiple calls to "train".

Specified by:
isIncremental in interface TrainableClassifier

clear

public void clear()
Clear all results of previous trainings (presumably so that this classifier can be trained again from scratch). This simply sets the current training set to null.

Specified by:
clear in interface TrainableClassifier

classify

public Classification classify(FeatureSet s)
                        throws ClassifierException
Compare the given example (features) to the examples in the training set and save the top K closest matches in ascending distance values.

Specified by:
classify in interface Classifier
Throws:
ClassifierException

main

public static void main(String[] argv)


Copyright © 2015 Central Laboratory of the Research Councils. All Rights Reserved.