May 2020
Intermediate to advanced
530 pages
17h 8m
English
The kNN classification algorithm in the Shark-ML library is implemented in the NearestNeighborModel class. An object of this class can be initialized with different nearest neighbor algorithms. The two main types are the brute-force option and the space partitioning trees option. In this sample, we will use the TreeNearestNeighbors algorithm, because it has better performance for medium-sized datasets. The following code block shows the use of the kNN algorithm with the Shark-ML library:
void KNNClassification(const ClassificationDataset& train, const ClassificationDataset& test, unsigned int num_classes) { KDTree<RealVector> tree(train.inputs()); TreeNearestNeighbors<RealVector, unsigned int> nn_alg(train, &tree); ...Read now
Unlock full access