Main Page   Class Hierarchy   Alphabetical List   Compound List   Compound Members  

prapi::kNNClassifier< T, I, C > Class Template Reference

#include <Classifier.h>

Inheritance diagram for prapi::kNNClassifier< T, I, C >:

prapi::Classifier< T, I, C > EventSource< ClassificationEvent< T, I, C > > Object List of all members.

Detailed Description

template<class T, class I = std::string, class C = int>
class prapi::kNNClassifier< T, I, C >

A k nearest neighbors classifier.

This classifier takes k nearest neighbors to a sample, according to a given proximity measure. The classification result is the class that has the majority in the k nearest neighbors. If there is a draw between two classes, then the closest one wins. If k equals to one, the classifier functions exactly as a nearest neighbor classifier does.


Public Methods

 kNNClassifier (util::List< Sample< T, I, C > > *trainingSamples, ProximityMeasure< T > *measure, int classCount, int k=1)
 Create a new kNN classifier with the given training samples, proximity measure, class count and k.

 kNNClassifier (util::List< Sample< T, I, C > > &trainingSamples, ProximityMeasure< T > *measure, int classCount, int k=1)
 Create a new kNN classifier with the given training samples, proximity measure, class count and k.

 kNNClassifier (util::List< Sample< T, I, C > > &trainingSamples, ProximityMeasure< T > &measure, int classCount, int k=1)
 Create a new kNN classifier with the given training samples, proximity measure, class count and k.

getClassification (Sample< T, I, C > &sample) throw (ClassificationException&)
 Get the classification for a single sample.

void setk (int newk)
 Set a new value for k.

int getk (void)
 Get the value of k.


Constructor & Destructor Documentation

template<class T, class I, class C>
prapi::kNNClassifier< T, I, C >::kNNClassifier util::List< Sample< T, I, C > > *    trainingSamples,
ProximityMeasure< T > *    measure,
int    classCount,
int    k = 1
 

Create a new kNN classifier with the given training samples, proximity measure, class count and k.

(Autorelease measure.)

template<class T, class I, class C>
prapi::kNNClassifier< T, I, C >::kNNClassifier util::List< Sample< T, I, C > > &    trainingSamples,
ProximityMeasure< T > *    measure,
int    classCount,
int    k = 1
 

Create a new kNN classifier with the given training samples, proximity measure, class count and k.

(Autorelease measure.)


Member Function Documentation

template<class T, class I, class C>
C prapi::kNNClassifier< T, I, C >::getClassification Sample< T, I, C > &    sample throw (ClassificationException&) [virtual]
 

Get the classification for a single sample.

This method is used by holdOut and leaveOneOut to classify each sample. Subclasses must override this method.

Parameters:
sample  the sample to be classified
Returns:
the classification. Simple classfiers (like NN or kNN) use integers. More sophisticated ones may use any classification type.
See also:
Sample for more information.

Implements prapi::Classifier< T, I, C >.

template<class T, class I, class C>
void prapi::kNNClassifier< T, I, C >::setk int    newk
 

Set a new value for k.

K is always ensured to be odd. That is, the least significant bit of k will always be turned on.


The documentation for this class was generated from the following file:
Documentation generated on 11.09.2003 with Doxygen.
The documentation is copyrighted material.
Copyright © Topi Mäenpää 2003. All rights reserved.