Cpp ML Library  1.0.0
A library of Machine Learning Algorithmns seen from the Udemy course Machine Learning A to Z.
Public Member Functions | List of all members
KNNClassifier Class Reference

K-Nearest Neighbors Classifier for classification tasks. More...

#include <KNNClassifier.hpp>

Public Member Functions

 KNNClassifier (int k=3)
 Constructs a KNNClassifier. More...
 
 ~KNNClassifier ()
 Destructor for KNNClassifier.
 
void fit (const std::vector< std::vector< double >> &X, const std::vector< int > &y)
 Fits the classifier to the training data. More...
 
std::vector< int > predict (const std::vector< std::vector< double >> &X) const
 Predicts class labels for the given input data. More...
 

Detailed Description

K-Nearest Neighbors Classifier for classification tasks.

Constructor & Destructor Documentation

◆ KNNClassifier()

KNNClassifier::KNNClassifier ( int  k = 3)
explicit

Constructs a KNNClassifier.

Parameters
kThe number of neighbors to consider.

Member Function Documentation

◆ fit()

void KNNClassifier::fit ( const std::vector< std::vector< double >> &  X,
const std::vector< int > &  y 
)

Fits the classifier to the training data.

Parameters
XA vector of feature vectors (training data).
yA vector of target class labels (training labels).

◆ predict()

std::vector< int > KNNClassifier::predict ( const std::vector< std::vector< double >> &  X) const

Predicts class labels for the given input data.

Parameters
XA vector of feature vectors (test data).
Returns
A vector of predicted class labels.

The documentation for this class was generated from the following file: