k-nearest neighbors algorithm
More...
#include <KNN.hpp>
|
void | getKNN (int *chosen_indices, const vector< double > &testie) |
| Finds the k-nearest neighbors of a data element. More...
|
|
k-nearest neighbors algorithm
Definition at line 22 of file KNN.hpp.
◆ Distance
Enumerator |
---|
HAMMING | |
EUCLIDEAN | |
Definition at line 24 of file KNN.hpp.
◆ KNN()
KNN::KNN |
( |
vector< vector< double >> |
data, |
|
|
int |
yColumn, |
|
|
int |
k = 1 , |
|
|
Distance |
distance = EUCLIDEAN |
|
) |
| |
|
inlineexplicit |
k-nearest neighbors algorithm, able to do regression and classification
- Parameters
-
data | a dataset, where each vector represents a data element |
yColumn | which column of the dataset is the dependent variable |
k | number of nearest neighbors |
Definition at line 98 of file KNN.hpp.
◆ classify() [1/2]
double KNN::classify |
( |
const vector< double > & |
testie | ) |
|
|
inline |
◆ classify() [2/2]
vector<double> KNN::classify |
( |
const vector< vector< double >> & |
test, |
|
|
bool |
verbose = false |
|
) |
| |
|
inline |
◆ euclidean()
double KNN::euclidean |
( |
vector< double > |
a, |
|
|
vector< double > |
b |
|
) |
| |
|
inline |
Calculates the Euclidean distance between two vectors.
- Parameters
-
a | first vector |
b | second vector |
- Returns
- Euclidean distance between a and b
Definition at line 120 of file KNN.hpp.
◆ getData()
const vector<vector<double> >& KNN::getData |
( |
| ) |
const |
|
inline |
◆ getDistance()
◆ getK()
◆ getKNN()
void KNN::getKNN |
( |
int * |
chosen_indices, |
|
|
const vector< double > & |
testie |
|
) |
| |
|
inlineprivate |
Finds the k-nearest neighbors of a data element.
- Parameters
-
chosen_indices | integer array that will keep the indices of the k-nearest neighbors |
testie | a vector of real values representing a data element |
Definition at line 34 of file KNN.hpp.
◆ getYColumn()
int KNN::getYColumn |
( |
| ) |
const |
|
inline |
◆ hamming()
double KNN::hamming |
( |
vector< double > |
a, |
|
|
vector< double > |
b |
|
) |
| |
|
inline |
Calculates the Hamming distance between two vectors.
- Parameters
-
a | first vector |
b | second vector |
- Returns
- Hamming distance between a and b
Definition at line 136 of file KNN.hpp.
◆ regression() [1/2]
double KNN::regression |
( |
const vector< double > & |
testie | ) |
|
|
inline |
Perform regression using.
- Parameters
-
- Returns
Definition at line 151 of file KNN.hpp.
◆ regression() [2/2]
vector<double> KNN::regression |
( |
const vector< vector< double >> & |
test, |
|
|
bool |
verbose = false |
|
) |
| |
|
inline |
◆ setDistance()
void KNN::setDistance |
( |
Distance |
distance | ) |
|
|
inline |
◆ setK()
◆ data
vector<vector<double> > KNN::data |
|
private |
◆ distance
◆ yColumn
The documentation for this class was generated from the following file: