O
- the type of DatabaseObjects 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.") public class KNNClassifier<O> extends AbstractDistanceBasedAlgorithm<O,Result> implements Classifier<O>
Modifier and Type | Class and Description |
---|---|
static class |
KNNClassifier.Parameterizer<O>
Parameterization class
|
Modifier and Type | Field and Description |
---|---|
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.
|
DISTANCE_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,
ArrayList<ClassLabel> labels) |
TypeInformation[] |
getInputTypeRestriction()
Get the input type restriction used for negotiating the data query.
|
protected Logging |
getLogger()
Get the (STATIC) logger for this class.
|
String |
model()
Produce a String representation of the classification model.
|
Result |
run(Database database)
Deprecated.
|
getDistanceFunction
makeParameterDistanceFunction
private static final Logging LOG
protected int k
protected Relation<? extends ClassLabel> labelrep
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)
Classifier
buildClassifier
in interface Classifier<O>
database
- the database to build the model onlabels
- the classes to be learnedpublic ClassLabel classify(O instance)
Classifier
classify
in interface Classifier<O>
instance
- an instance to classifypublic double[] classProbabilities(O instance, ArrayList<ClassLabel> labels)
public String model()
Classifier
model
in interface Classifier<O>
@Deprecated public Result run(Database database) throws IllegalStateException
Algorithm
run
in interface Algorithm
run
in class AbstractAlgorithm<Result>
database
- the database to run the algorithm onIllegalStateException
public TypeInformation[] getInputTypeRestriction()
AbstractAlgorithm
getInputTypeRestriction
in interface Algorithm
getInputTypeRestriction
in class AbstractAlgorithm<Result>
protected Logging getLogger()
AbstractAlgorithm
getLogger
in class AbstractAlgorithm<Result>
Copyright © 2015 ELKI Development Team, Lehr- und Forschungseinheit für Datenbanksysteme, Ludwig-Maximilians-Universität München. License information.