#include <knnClassification.h>
Public Member Functions | |
knnClassification (const int &num_inputs, const std::vector< size_t > &which_inputs, const std::vector< trainingExampleTemplate< T > > &trainingSet, const int k) | |
~knnClassification () | |
void | addNeighbour (const int &classNum, const std::vector< T > &features) |
T | run (const std::vector< T > &inputVector) override |
void | train (const std::vector< trainingExampleTemplate< T > > &trainingSet) override |
void | train (const std::vector< trainingExampleTemplate< T > > &trainingSet, const std::size_t whichOutput) override |
void | reset () override |
size_t | getNumInputs () const override |
std::vector< size_t > | getWhichInputs () const override |
int | getK () const |
void | setK (int newK) |
void | getJSONDescription (Json::Value ¤tModel) override |
Public Member Functions inherited from baseModel< T > | |
virtual | ~baseModel () |
Additional Inherited Members | |
Protected Member Functions inherited from baseModel< T > | |
template<typename TT , class Dummy = int> | |
Json::Value | vector2json (TT vec) |
template<class Dummy = int> | |
Json::Value | vector2json (std::vector< unsigned long > vec) |
Class for implementing a knn classifier
knnClassification< T >::knnClassification | ( | const int & | num_inputs, |
const std::vector< size_t > & | which_inputs, | ||
const std::vector< trainingExampleTemplate< T > > & | trainingSet, | ||
const int | k | ||
) |
Constructor that takes training examples in
int | Number of inputs expected in the training and input vectors |
vector | of input numbers to be fed into the classifer. |
vector | of training examples |
int | how many near neighbours to evaluate |
knnClassification< T >::~knnClassification |
void knnClassification< T >::addNeighbour | ( | const int & | classNum, |
const std::vector< T > & | features | ||
) |
add another example to the existing training set
class | number of example |
feature | vector of example |
|
overridevirtual |
Populate a JSON value with a description of the current model
A | JSON value to be populated |
Implements baseModel< T >.
int knnClassification< T >::getK |
Get the number of nearest neighbours used by the kNN algorithm.
|
overridevirtual |
Find out how many inputs the model expects
Implements baseModel< T >.
|
overridevirtual |
Find out which inputs in a vector will be used
Implements baseModel< T >.
|
overridevirtual |
Reset the model to its empty state.
Implements baseModel< T >.
|
overridevirtual |
Generate an output value from a single input vector.
A | standard vector of type T to be evaluated. |
Implements baseModel< T >.
void knnClassification< T >::setK | ( | int | newK | ) |
Change the number of nearest neighbours used by the kNN algorithm.
new | value for k |
|
overridevirtual |
Fill the model with a vector of examples.
The | training set is a vector of training examples that contain both a vector of input values and a value specifying desired output class. |
Implements baseModel< T >.
|
overridevirtual |
Fill the model with a vector of examples. Use this when the model is part of a modelSet.
The | training set is a vector of training examples that contain both a vector of input values and a value specifying desired output class. |
Implements baseModel< T >.