KMeans {less}R Documentation

KMeans Clustering

Description

Wrapper R6 Class of stats::kmeans function that can be used for LESSRegressor and LESSClassifier

Value

R6 Class of KMeans

Super class

less::BaseEstimator -> KMeans

Methods

Public methods

Inherited methods

Method new()

Creates a new instance of R6 Class of KMeans

Usage
KMeans$new(n_clusters = 8, n_init = 10, max_iter = 300, random_state = NULL)
Arguments
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).

Examples
km <- KMeans$new()
km <- KMeans$new(n_clusters = 10)
km <- KMeans$new(n_clusters = 10, random_state = 100)

Method fit()

Perform k-means clustering on a data matrix.

Usage
KMeans$fit(X)
Arguments
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).

Returns

Fitted R6 class of KMeans() that has 'cluster_centers' and 'labels' attributes

Examples
data(abalone)
km <- KMeans$new()
km$fit(abalone[1:100,])

Method get_cluster_centers()

Auxiliary function returning the cluster centers

Usage
KMeans$get_cluster_centers()
Examples
print(km$get_cluster_centers())

Method get_labels()

Auxiliary function returning a vector of integers (from 1:k) indicating the cluster to which each point is allocated.

Usage
KMeans$get_labels()
Examples
print(km$get_labels())

Method clone()

The objects of this class are cloneable with this method.

Usage
KMeans$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

See Also

stats::kmeans()

Examples


## ------------------------------------------------
## 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())

[Package less version 0.1.0 Index]