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>
distance
Distance functionprotected int
k
Holds the value of @link #K_PARAM}.protected KNNSearcher<O>
knnq
kNN query class.protected Relation<? extends ClassLabel>
labelrep
Class 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 void
buildClassifier(Database database, Relation<? extends ClassLabel> labels)
Performs the training.ClassLabel
classify(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.String
model()
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:Algorithm
Get the input type restriction used for negotiating the data query.- Specified by:
getInputTypeRestriction
in interfaceAlgorithm
- Returns:
- Type restriction
-
buildClassifier
public void buildClassifier(Database database, Relation<? extends ClassLabel> labels)
Description copied from interface:Classifier
Performs the training. Sets available labels.- Specified by:
buildClassifier
in 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:Classifier
Classify a single instance.- Specified by:
classify
in 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:Classifier
Produce a String representation of the classification model.- Specified by:
model
in interfaceClassifier<O>
- Returns:
- a String representation of the classification model
-
-