yat  0.14.5pre
Public Member Functions | List of all members
theplu::yat::classifier::NCC< Distance > Class Template Reference

Nearest Centroid Classifier. More...

#include <yat/classifier/NCC.h>

Inheritance diagram for theplu::yat::classifier::NCC< Distance >:
theplu::yat::classifier::SupervisedClassifier

Public Member Functions

 NCC (void)
 Constructor. More...
 
 NCC (const Distance &)
 Constructor using an initialized distance measure. More...
 
virtual ~NCC (void)
 
const utility::Matrixcentroids (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...
 

Detailed Description

template<typename Distance>
class theplu::yat::classifier::NCC< Distance >

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.

Constructor & Destructor Documentation

template<typename Distance >
theplu::yat::classifier::NCC< Distance >::NCC ( void  )

Constructor.

Distance is initialized using its default constructor.

template<typename Distance >
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.

template<typename Distance >
theplu::yat::classifier::NCC< Distance >::~NCC ( void  )
virtual

Destructor

Member Function Documentation

template<typename Distance >
const utility::Matrix & theplu::yat::classifier::NCC< Distance >::centroids ( void  ) const

Get the centroids for all classes.

Returns
The centroids for each class as columns in a matrix.
template<typename Distance >
NCC< Distance > * theplu::yat::classifier::NCC< Distance >::make_classifier ( void  ) const
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.

Returns
A dynamically allocated classifier, which has to be deleted by the caller to avoid memory leaks.

Implements theplu::yat::classifier::SupervisedClassifier.

template<typename Distance >
void theplu::yat::classifier::NCC< Distance >::predict ( const MatrixLookup data,
utility::Matrix results 
) const
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.

Note
NCC returns distances to centroids as the prediction. This means that the best class for a sample has the smallest value in results. This is in contrast to, for example, KNN for which the best class for a sample in results has the largest number (the largest number of nearest neighbors).

Implements theplu::yat::classifier::SupervisedClassifier.

template<typename Distance >
void theplu::yat::classifier::NCC< Distance >::predict ( const MatrixLookupWeighted data,
utility::Matrix results 
) const
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.

Note
NCC returns distances to centroids as the prediction. This means that the best class for a sample has the smallest value in results. This is in contrast to, for example, KNN for which the best class for a sample in results has the largest number (the largest number of nearest neighbors).

Implements theplu::yat::classifier::SupervisedClassifier.

template<typename Distance >
void theplu::yat::classifier::NCC< Distance >::train ( const MatrixLookup data,
const Target targets 
)
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.

template<typename Distance >
void theplu::yat::classifier::NCC< Distance >::train ( const MatrixLookupWeighted data,
const Target targets 
)
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.


The documentation for this class was generated from the following file:

Generated on Tue Sep 26 2017 02:33:29 for yat by  doxygen 1.8.5