K-means clustering utility that partitions samples into the requested number of clusters. More...
#include <kmeans.h>
Public Member Functions | |
| KMeans (Index clusters=3, Index=100) | |
| Builds a K-means instance with the given cluster count and maximum number of iterations. | |
| VectorI | calculate_outputs (const MatrixR &) |
| Assigns each row of the input matrix to its nearest cluster. | |
| VectorR | elbow_method (const MatrixR &, Index=10) |
| Runs the elbow method on the supplied data over a range of cluster counts. | |
| Index | find_optimal_clusters (const VectorR &) const |
| Returns the cluster count located at the elbow of the supplied distortion curve. | |
| VectorI | get_cluster_labels () const |
| Returns the cluster label assigned to each fitted sample. | |
| MatrixR | get_cluster_centers () const |
| Returns the centroid of each cluster as rows of the returned matrix. | |
| Index | get_clusters_number () const |
| Returns the number of clusters configured for the algorithm. | |
| void | fit (const MatrixR &) |
| Fits the K-means model on the supplied data matrix. | |
| void | set_cluster_number (const Index) |
| Sets the desired number of clusters. | |
| void | set_centers_random (const MatrixR &) |
| Initializes cluster centres by sampling at random from the supplied data. | |
Detailed Description
K-means clustering utility that partitions samples into the requested number of clusters.
Constructor & Destructor Documentation
◆ KMeans()
| opennn::KMeans::KMeans | ( | Index | clusters = 3, |
| Index | = 100 ) |
Builds a K-means instance with the given cluster count and maximum number of iterations.
Member Function Documentation
◆ calculate_outputs()
Assigns each row of the input matrix to its nearest cluster.
- Returns
- Vector with the cluster index for every row.
◆ elbow_method()
Runs the elbow method on the supplied data over a range of cluster counts.
- Returns
- Vector with the within-cluster distortion for each tested cluster count.
◆ find_optimal_clusters()
| Index opennn::KMeans::find_optimal_clusters | ( | const VectorR & | ) | const |
Returns the cluster count located at the elbow of the supplied distortion curve.
◆ fit()
| void opennn::KMeans::fit | ( | const MatrixR & | ) |
Fits the K-means model on the supplied data matrix.
◆ get_cluster_centers()
| MatrixR opennn::KMeans::get_cluster_centers | ( | ) | const |
Returns the centroid of each cluster as rows of the returned matrix.
◆ get_cluster_labels()
| VectorI opennn::KMeans::get_cluster_labels | ( | ) | const |
Returns the cluster label assigned to each fitted sample.
◆ get_clusters_number()
| Index opennn::KMeans::get_clusters_number | ( | ) | const |
Returns the number of clusters configured for the algorithm.
◆ set_centers_random()
| void opennn::KMeans::set_centers_random | ( | const MatrixR & | ) |
Initializes cluster centres by sampling at random from the supplied data.
◆ set_cluster_number()
| void opennn::KMeans::set_cluster_number | ( | const Index | ) |
Sets the desired number of clusters.