O - the type of objects handled by this algorithm@Title(value="kNN-classifier") @Description(value="Lazy classifier classifies a given instance to the majority class of the k-nearest neighbors.") @Priority(value=100) public class KNNClassifier<O> extends AbstractAlgorithm<Result> implements DistanceBasedAlgorithm<O>, Classifier<O>
| Modifier and Type | Class and Description | 
|---|---|
static class  | 
KNNClassifier.Parameterizer<O>
Parameterization class 
 | 
| Modifier and Type | Field and Description | 
|---|---|
protected DistanceFunction<? super O> | 
distanceFunction
Distance function 
 | 
protected int | 
k
Holds the value of @link #K_PARAM}. 
 | 
protected KNNQuery<O> | 
knnq
kNN query class. 
 | 
protected Relation<? extends ClassLabel> | 
labelrep
Class label representation. 
 | 
private static Logging | 
LOG
The logger for this class. 
 | 
ALGORITHM_IDDISTANCE_FUNCTION_ID| Constructor and Description | 
|---|
KNNClassifier(DistanceFunction<? super O> distanceFunction,
             int k)
Constructor. 
 | 
| Modifier and Type | Method and 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)  | 
DistanceFunction<? super O> | 
getDistanceFunction()
Returns the distanceFunction. 
 | 
TypeInformation[] | 
getInputTypeRestriction()
Get the input type restriction used for negotiating the data query. 
 | 
protected Logging | 
getLogger()
Get the (STATIC) logger for this class. 
 | 
java.lang.String | 
model()
Produce a String representation of the classification model. 
 | 
Result | 
run(Database database)
Deprecated.  
 | 
private static final Logging LOG
protected int k
protected Relation<? extends ClassLabel> labelrep
protected DistanceFunction<? super O> distanceFunction
public KNNClassifier(DistanceFunction<? super O> distanceFunction, int k)
distanceFunction - Distance functionk - Number of nearest neighbors to access.public void buildClassifier(Database database, Relation<? extends ClassLabel> labels)
ClassifierbuildClassifier in interface Classifier<O>database - the database to build the model onlabels - the classes to be learnedpublic ClassLabel classify(O instance)
Classifierclassify in interface Classifier<O>instance - an instance to classifypublic double[] classProbabilities(O instance, java.util.ArrayList<ClassLabel> labels)
public java.lang.String model()
Classifiermodel in interface Classifier<O>@Deprecated public Result run(Database database) throws java.lang.IllegalStateException
Algorithmrun in interface Algorithmrun in class AbstractAlgorithm<Result>database - the database to run the algorithm onjava.lang.IllegalStateExceptionpublic DistanceFunction<? super O> getDistanceFunction()
DistanceBasedAlgorithmgetDistanceFunction in interface DistanceBasedAlgorithm<O>public TypeInformation[] getInputTypeRestriction()
AbstractAlgorithmgetInputTypeRestriction in interface AlgorithmgetInputTypeRestriction in class AbstractAlgorithm<Result>protected Logging getLogger()
AbstractAlgorithmgetLogger in class AbstractAlgorithm<Result>Copyright © 2019 ELKI Development Team. License information.