
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.
|
getDistanceFunctionmakeParameterDistanceFunctionprivate 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)
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, ArrayList<ClassLabel> labels)
public String model()
Classifiermodel in interface Classifier<O>@Deprecated public Result run(Database database) throws IllegalStateException
Algorithmrun in interface Algorithmrun in class AbstractAlgorithm<Result>database - the database to run the algorithm onIllegalStateExceptionpublic TypeInformation[] getInputTypeRestriction()
AbstractAlgorithmgetInputTypeRestriction in interface AlgorithmgetInputTypeRestriction in class AbstractAlgorithm<Result>protected Logging getLogger()
AbstractAlgorithmgetLogger in class AbstractAlgorithm<Result>Copyright © 2015 ELKI Development Team, Lehr- und Forschungseinheit für Datenbanksysteme, Ludwig-Maximilians-Universität München. License information.