hhreco.classification
Class KNNClassifier

java.lang.Object
  extended byhhreco.classification.KNNClassifier
All Implemented Interfaces:
Classifier, TrainableClassifier

public class KNNClassifier
extends java.lang.Object
implements TrainableClassifier

This K-nearest neighbor classifier compares a test example with every example in the training set by computing the normalized Euclidean distance.


Constructor Summary
KNNClassifier()
           
 
Method Summary
 Classification classify(FeatureSet s)
          Classify the given example by testing it against each example in the training set.
 void clear()
          Remove previously trained data.
 boolean isIncremental()
          Return whether this classifier is incremental, i.e.
 void train(TrainingSet s, int numFeatures)
          Train the classifier with a given training set.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

KNNClassifier

public KNNClassifier()
Method Detail

classify

public Classification classify(FeatureSet s)
                        throws ClassifierException
Classify the given example by testing it against each example in the training set.

Specified by:
classify in interface Classifier
Throws:
ClassifierException

train

public void train(TrainingSet s,
                  int numFeatures)
           throws ClassifierException
Train the classifier with a given training set. This method will throw a ClassifierException if the training set is not self consisistent, i.e. the feature sets that it contains do not have the same number of features in them. Any previously training data, if any, will be removed upon the call of this method.

Specified by:
train in interface TrainableClassifier
Throws:
ClassifierException

isIncremental

public boolean isIncremental()
Return whether this classifier is incremental, i.e. whether new data can be added to the existing training set (A) without reprocessing the examples in A.

Specified by:
isIncremental in interface TrainableClassifier

clear

public void clear()
Remove previously trained data.

Specified by:
clear in interface TrainableClassifier