KMeans | R Documentation |
Wrapper R6 Class of stats::kmeans function that can be used for LESSRegressor and LESSClassifier
R6 Class of KMeans
less::BaseEstimator
-> KMeans
new()
Creates a new instance of R6 Class of KMeans
KMeans$new(n_clusters = 8, n_init = 10, max_iter = 300, random_state = NULL)
n_clusters
the number of clusters. A random set of (distinct) rows in X is chosen as the initial centres (default to 8)
n_init
how many random sets should be chosen? (default to 10)
max_iter
the maximum number of iterations allowed (default to 300).
random_state
seed number to be used for fixing the randomness (default to NULL).
km <- KMeans$new() km <- KMeans$new(n_clusters = 10) km <- KMeans$new(n_clusters = 10, random_state = 100)
fit()
Perform k-means clustering on a data matrix.
KMeans$fit(X)
X
numeric matrix of data, or an object that can be coerced to such a matrix (such as a numeric vector or a data frame with all numeric columns).
Fitted R6 class of KMeans() that has 'cluster_centers' and 'labels' attributes
data(abalone) km <- KMeans$new() km$fit(abalone[1:100,])
get_cluster_centers()
Auxiliary function returning the cluster centers
KMeans$get_cluster_centers()
print(km$get_cluster_centers())
get_labels()
Auxiliary function returning a vector of integers (from 1:k) indicating the cluster to which each point is allocated.
KMeans$get_labels()
print(km$get_labels())
clone()
The objects of this class are cloneable with this method.
KMeans$clone(deep = FALSE)
deep
Whether to make a deep clone.
stats::kmeans()
## ------------------------------------------------ ## Method `KMeans$new` ## ------------------------------------------------ km <- KMeans$new() km <- KMeans$new(n_clusters = 10) km <- KMeans$new(n_clusters = 10, random_state = 100) ## ------------------------------------------------ ## Method `KMeans$fit` ## ------------------------------------------------ data(abalone) km <- KMeans$new() km$fit(abalone[1:100,]) ## ------------------------------------------------ ## Method `KMeans$get_cluster_centers` ## ------------------------------------------------ print(km$get_cluster_centers()) ## ------------------------------------------------ ## Method `KMeans$get_labels` ## ------------------------------------------------ print(km$get_labels())
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.