Xmipp
v3.23.11-Nereus
|
#include <knn_classifier.h>
Public Types | |
enum | distType { EUCLIDEAN = 0, CITYBLOCK = 1 } |
Type of distance. More... | |
Public Member Functions | |
KNN (int k) | |
void | train (MultidimArray< double > &dataset, MultidimArray< double > &dataLabel, MultidimArray< double > &labelset) |
int | predict (MultidimArray< double > &sample, double &score) |
void | KNearestNeighbors (MultidimArray< double > &sample) |
Compute the K nearest neighbors to the sample. More... | |
void | setK (int k) |
Method for setting the K. More... | |
This class implements KNN (K Nearest Neighbors). It does the classification by a voting of nearest neighbors of the point. It uses the exhaustive search in order to find the nearest neighbors.
Definition at line 41 of file knn_classifier.h.
enum KNN::distType |
Type of distance.
Enumerator | |
---|---|
EUCLIDEAN | |
CITYBLOCK |
Definition at line 45 of file knn_classifier.h.
KNN::KNN | ( | int | k | ) |
Constructs the algorithm Parameter: k The number of nearest neighbors
Definition at line 28 of file knn_classifier.cpp.
void KNN::KNearestNeighbors | ( | MultidimArray< double > & | sample | ) |
Compute the K nearest neighbors to the sample.
Definition at line 42 of file knn_classifier.cpp.
int KNN::predict | ( | MultidimArray< double > & | sample, |
double & | score | ||
) |
Get an item an predict the related class of that by doing the voting among its neighbors.
Definition at line 70 of file knn_classifier.cpp.
void KNN::setK | ( | int | k | ) |
Method for setting the K.
Definition at line 193 of file knn_classifier.cpp.
void KNN::train | ( | MultidimArray< double > & | dataset, |
MultidimArray< double > & | dataLabel, | ||
MultidimArray< double > & | labelset | ||
) |
Now actually there is no training step.In future more complex train step can be added.
Definition at line 34 of file knn_classifier.cpp.