TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
|
Implementation of [K-Nearest Neighbors algorithm] (https://en.wikipedia.org/wiki/K-nearest_neighbors_algorithm). More...
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <numeric>
#include <unordered_map>
#include <vector>
Go to the source code of this file.
Classes | |
class | machine_learning::k_nearest_neighbors::Knn |
K-Nearest Neighbors (Knn) class using Euclidean distance as distance metric. More... | |
Namespaces | |
namespace | machine_learning |
A* search algorithm | |
namespace | k_nearest_neighbors |
Functions for the [K-Nearest Neighbors algorithm] (https://en.wikipedia.org/wiki/K-nearest_neighbors_algorithm) implementation. | |
Functions | |
template<typename T > | |
double | machine_learning::k_nearest_neighbors::euclidean_distance (const std::vector< T > &a, const std::vector< T > &b) |
Compute the Euclidean distance between two vectors. | |
static void | test () |
Self-test implementations. | |
int | main (int argc, char *argv[]) |
Main function. | |
Implementation of [K-Nearest Neighbors algorithm] (https://en.wikipedia.org/wiki/K-nearest_neighbors_algorithm).
K-nearest neighbors algorithm, also known as KNN or k-NN, is a supervised learning classifier, which uses proximity to make classifications. This implementantion uses the Euclidean Distance as distance metric to find the K-nearest neighbors.
Definition in file k_nearest_neighbors.cpp.
double machine_learning::k_nearest_neighbors::euclidean_distance | ( | const std::vector< T > & | a, |
const std::vector< T > & | b ) |
Compute the Euclidean distance between two vectors.
T | typename of the vector |
a | first unidimentional vector |
b | second unidimentional vector |
Definition at line 43 of file k_nearest_neighbors.cpp.
int main | ( | int | argc, |
char * | argv[] ) |
Main function.
argc | commandline argument count (ignored) |
argv | commandline array of arguments (ignored) |
Definition at line 193 of file k_nearest_neighbors.cpp.
|
static |
Self-test implementations.
Definition at line 140 of file k_nearest_neighbors.cpp.