Package elki.classification
Class KNNClassifier<O>
- java.lang.Object
-
- elki.classification.KNNClassifier<O>
-
- Type Parameters:
O- the type of objects handled by this algorithm
- All Implemented Interfaces:
Algorithm,Classifier<O>
@Title("kNN-classifier") @Description("Lazy classifier classifies a given instance to the majority class of the k-nearest neighbors.") @Priority(100) public class KNNClassifier<O> extends java.lang.Object implements Classifier<O>
KNNClassifier classifies instances based on the class distribution among the k nearest neighbors in a database.- Since:
- 0.7.0
- Author:
- Arthur Zimek
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface elki.Algorithm
Algorithm.Utils
-
-
Field Summary
Fields Modifier and Type Field Description protected Distance<? super O>distanceDistance functionprotected intkHolds the value of @link #K_PARAM}.protected KNNSearcher<O>knnqkNN query class.protected Relation<? extends ClassLabel>labelrepClass label representation.
-
Constructor Summary
Constructors Constructor Description KNNClassifier(Distance<? super O> distance, int k)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidbuildClassifier(Database database, Relation<? extends ClassLabel> labels)Performs the training.ClassLabelclassify(O instance)Classify a single instance.double[]classProbabilities(O instance, java.util.ArrayList<ClassLabel> labels)Distance<? super O>getDistance()Returns the distance.TypeInformation[]getInputTypeRestriction()Get the input type restriction used for negotiating the data query.java.lang.Stringmodel()Produce a String representation of the classification model.
-
-
-
Field Detail
-
k
protected int k
Holds the value of @link #K_PARAM}.
-
knnq
protected KNNSearcher<O> knnq
kNN query class.
-
labelrep
protected Relation<? extends ClassLabel> labelrep
Class label representation.
-
-
Method Detail
-
getInputTypeRestriction
public TypeInformation[] getInputTypeRestriction()
Description copied from interface:AlgorithmGet the input type restriction used for negotiating the data query.- Specified by:
getInputTypeRestrictionin interfaceAlgorithm- Returns:
- Type restriction
-
buildClassifier
public void buildClassifier(Database database, Relation<? extends ClassLabel> labels)
Description copied from interface:ClassifierPerforms the training. Sets available labels.- Specified by:
buildClassifierin interfaceClassifier<O>- Parameters:
database- the database to build the model onlabels- the classes to be learned
-
classify
public ClassLabel classify(O instance)
Description copied from interface:ClassifierClassify a single instance.- Specified by:
classifyin interfaceClassifier<O>- Parameters:
instance- an instance to classify- Returns:
- predicted class label of the given instance
-
classProbabilities
public double[] classProbabilities(O instance, java.util.ArrayList<ClassLabel> labels)
-
model
public java.lang.String model()
Description copied from interface:ClassifierProduce a String representation of the classification model.- Specified by:
modelin interfaceClassifier<O>- Returns:
- a String representation of the classification model
-
-