yat
0.14.5pre
|
Nearest Centroid Classifier. More...
#include <yat/classifier/NCC.h>
Public Member Functions | |
NCC (void) | |
Constructor. More... | |
NCC (const Distance &) | |
Constructor using an initialized distance measure. More... | |
virtual | ~NCC (void) |
const utility::Matrix & | centroids (void) const |
Get the centroids for all classes. More... | |
NCC< Distance > * | make_classifier (void) const |
Create an untrained copy of the classifier. More... | |
void | predict (const MatrixLookup &data, utility::Matrix &results) const |
Make predictions for unweighted test data. More... | |
void | predict (const MatrixLookupWeighted &data, utility::Matrix &results) const |
Make predictions for weighted test data. More... | |
void | train (const MatrixLookup &data, const Target &targets) |
Train the NCC using unweighted training data with known targets. More... | |
void | train (const MatrixLookupWeighted &data, const Target &targets) |
Train the NCC using weighted training data with known targets. More... | |
Nearest Centroid Classifier.
A sample is predicted based on its distance to centroids for each class. The centroids are generated using training data. NCC supports using different measures, for example, Euclidean distance, to define distance between samples and centroids.
The template argument Distance should be a class modelling the concept Distance.
theplu::yat::classifier::NCC< Distance >::NCC | ( | void | ) |
Constructor.
Distance is initialized using its default constructor.
theplu::yat::classifier::NCC< Distance >::NCC | ( | const Distance & | dist | ) |
Constructor using an initialized distance measure.
This constructor should be used if Distance has parameters and the user wants to specify the parameters by initializing Distance prior to constructing the NCC.
|
virtual |
Destructor
const utility::Matrix & theplu::yat::classifier::NCC< Distance >::centroids | ( | void | ) | const |
Get the centroids for all classes.
|
virtual |
Create an untrained copy of the classifier.
An interface for making new classifier objects. This function allows for specification at run-time of which classifier type to instatiate (see 'Prototype' in Design Patterns). Derived classes should implement this function with DerivedClass* as the return type and not SupervisedClassifier*. A dynamically allocated DerivedClassifier should be returned. The implementation of this function should correspond to a copy constructor with the exception that the returned classifier is not trained.
Implements theplu::yat::classifier::SupervisedClassifier.
|
virtual |
Make predictions for unweighted test data.
Predictions are calculated and returned in results. For each sample in data, results contains the distances to the centroids for each class. If a class has no training samples NaN's are returned for this class in results. Weighted distance calculations, in which NaN's have zero weights, are used if the centroids contain NaN's.
Implements theplu::yat::classifier::SupervisedClassifier.
|
virtual |
Make predictions for weighted test data.
Predictions are calculated and returned in results. For each sample in data, results contains the distances to the centroids for each class as in predict(const MatrixLookup& data, utility::Matrix& results). Weighted distance calculations are used, and zero weights are used for NaN's in centroids. If for a test sample and centroid pair, all variables have either zero weight for the test sample or NaN for the centroid, the centroid and the sample have no variables with values in common. In this case the prediction for the sample is set to NaN for the class in results.
Implements theplu::yat::classifier::SupervisedClassifier.
|
virtual |
Train the NCC using unweighted training data with known targets.
A centroid is calculated for each class. For each variable in data, a centroid for a class contains the average value of the variable across all training samples in the class.
Implements theplu::yat::classifier::SupervisedClassifier.
|
virtual |
Train the NCC using weighted training data with known targets.
A centroid is calculated for each class as in train(const MatrixLookup&, const Target&). The weights of the data are used when calculating the centroids and the centroids should be interpreted as unweighted (i.e. centroid values have unity weights). If a variable has zero weights for all samples in a class, the centroid is set to NaN for that variable.
Implements theplu::yat::classifier::SupervisedClassifier.