classPiiKnnClassifier
#include <PiiKnnClassifier.h>
K nearest neighbors classifier.
Inherits PiiVectorQuantizer< SampleSet >
Description
The k-NN classifier considers the k code vectors closest to an unknown sample. The winning class index is chosen by voting among the k closest neighbors.
Public types
|
typedef PiiSampleSet::Traits< SampleSet
>::ConstFeatureIterator
|
Constructors and destructor
|
(
Creates a new k-NN classifier that uses measure to measure distances between samples. |
|
|
( )
Creates a new k-NN classifier with the default distance measure (PiiSquaredGeometricDistance). |
|
Public member functions
|
virtual double
|
(
Returns the class label of the closest model sample. |
|
QVector<
double > &
|
( )
Returns a modifiable reference to the class labels. |
|
QVector<
double >
|
( )
Returns the class labels. |
|
virtual int
|
(
Returns the index of the closest model sample in the winning class selected by the k nearest neighbors rule. |
|
int
|
( )
Returns the the current value for k. |
|
void
|
Sets the class labels. |
|
void
|
(
Sets the number of closest neighbors to find when classifying an unknown sample. |
Function details
-
PiiKnnClassifier
(- PiiDistanceMeasure< SampleSet > * measure
Creates a new k-NN classifier that uses measure to measure distances between samples.
The value for k is initialized to 5.
-
PiiKnnClassifier
()Creates a new k-NN classifier with the default distance measure (PiiSquaredGeometricDistance).
The value for k is initialized to 5.
-
~PiiKnnClassifier
() -
virtual double classify
(- ConstFeatureIterator featureVector
[virtual]Returns the class label of the closest model sample.
If the distance to the closest sample is too large (see PiiVectorQuantizer::setRejectTreshold()), or there is no class label for the closest sample,
NaNwill be returned.Reimplemented from PiiVectorQuantizer.
-
QVector< double > & classLabels
()Returns a modifiable reference to the class labels.
-
QVector< double > classLabels
()Returns the class labels.
-
virtual int findClosestMatch
(- ConstFeatureIterator featureVector
- double * distance
[virtual]Returns the index of the closest model sample in the winning class selected by the k nearest neighbors rule.
Reimplemented from PiiVectorQuantizer.
-
int getK
()Returns the the current value for k.
-
void setClassLabels
Sets the class labels.
-
void setK
(- int k
Sets the number of closest neighbors to find when classifying an unknown sample.
If k is set to one, the classifier works as a nearest-neighbor classifier.
Add a note
Not a single note added yet. Be the first, add yours.