#include <kmeans.h>
|
| kmeans (std::vector< std::vector< double > > data, int K, int64_t MAX_ITER=1500) |
| Constructor for the kmeans class.
|
|
| ~kmeans () |
| Destroy the kmeans object.
|
|
void | assign_to_closest (std::vector< double > &x) |
|
std::vector< double > | get_centroid (std::vector< std::vector< double > > cluster) |
|
std::pair< std::vector< std::vector< double > >, std::map< std::vector< double >, int64_t > > | fit () |
|
|
| data = fill_data() |
|
int | CLUSTERS = 3 |
|
dict | data_dict |
|
| json_object = json.dumps(data_dict) |
|
| input_name = open("info.json", 'r') |
|
| file = json.load(input_name) |
|
| centroids = file['centroids'] |
|
| assignments = file['assignments'] |
|
list | COLORS = ["red", "green", "orange", "blue", "black", "brown", "purple"] |
|
| x |
|
| y |
|
| x_noise |
|
| y_noise |
|
int | i = 0 |
|
| x_centroids |
|
| y_centroids |
|
| colors |
|
| color |
|
@ brief Class for the kmeans clustering algorithm
◆ kmeans()
kmeans::kmeans |
( |
std::vector< std::vector< double > > | data, |
|
|
int | K, |
|
|
int64_t | MAX_ITER = 1500 ) |
|
inline |
Constructor for the kmeans class.
- Parameters
-
data | the input data(2D vector) |
K | the number of clusters |
MAX_ITER | default 500, maximum iterations till it converges |
◆ assign_to_closest()
void kmeans::assign_to_closest |
( |
std::vector< double > & | x | ) |
|
|
inline |
@ brief assign_to_closest function assigns the closest centroid to point x @ param x: the input vector
◆ fit()
std::pair< std::vector< std::vector< double > >, std::map< std::vector< double >, int64_t > > kmeans::fit |
( |
| ) |
|
|
inline |
@ brief fit function @ return pair<vector<int64_t>, map<int64_t, int> >: the centroids and the assignments of the clustering algorithm
◆ get_centroid()
std::vector< double > kmeans::get_centroid |
( |
std::vector< std::vector< double > > | cluster | ) |
|
|
inline |
@ brief get_centroid function @ param cluster: the input cluster @ return vector<int>: the centroid of the cluster
◆ data_dict
The documentation for this class was generated from the following files:
- /Users/runner/work/AlgoPlus/AlgoPlus/src/machine_learning/clustering/kmeans/kmeans.h
- /Users/runner/work/AlgoPlus/AlgoPlus/examples/machine_learning/clustering/kmeans/kmeans.py