Cpp ML Library
1.0.0
A library of Machine Learning Algorithmns seen from the Udemy course Machine Learning A to Z.
|
Implements the K-Means clustering algorithm with K-Means++ initialization. More...
#include <KMeans.hpp>
Public Member Functions | |
KMeans (int n_clusters=8, int max_iter=300, double tol=1e-4, unsigned int random_state=0) | |
Constructs a KMeans object. More... | |
~KMeans () | |
Destructor for KMeans. | |
void | fit (const std::vector< std::vector< double >> &X) |
Fits the KMeans model to the data. More... | |
std::vector< int > | predict (const std::vector< std::vector< double >> &X) const |
Predicts the closest cluster each sample in X belongs to. More... | |
const std::vector< std::vector< double > > & | get_cluster_centers () const |
Returns the cluster centers. More... | |
Implements the K-Means clustering algorithm with K-Means++ initialization.
KMeans::KMeans | ( | int | n_clusters = 8 , |
int | max_iter = 300 , |
||
double | tol = 1e-4 , |
||
unsigned int | random_state = 0 |
||
) |
Constructs a KMeans object.
n_clusters | The number of clusters to form. |
max_iter | The maximum number of iterations. |
tol | The tolerance to declare convergence. |
random_state | Seed for random number generator (optional). |
void KMeans::fit | ( | const std::vector< std::vector< double >> & | X | ) |
Fits the KMeans model to the data.
X | A vector of feature vectors. |
const std::vector< std::vector< double > > & KMeans::get_cluster_centers | ( | ) | const |
Returns the cluster centers.
std::vector< int > KMeans::predict | ( | const std::vector< std::vector< double >> & | X | ) | const |
Predicts the closest cluster each sample in X belongs to.
X | A vector of feature vectors. |