Skip to contents

Compute performance indices for clustering solutions.

Usage

cluster_performance(model, ...)

# S3 method for kmeans
cluster_performance(model, ...)

# S3 method for hclust
cluster_performance(model, data, clusters, ...)

# S3 method for dbscan
cluster_performance(model, data, ...)

# S3 method for parameters_clusters
cluster_performance(model, ...)

Arguments

model

Cluster model.

...

Arguments passed to or from other methods.

data

A data.frame.

clusters

A vector with clusters assignments (must be same length as rows in data).

Examples

# kmeans
model <- kmeans(iris[1:4], 3)
cluster_performance(model)
#> # Indices of model performance
#> 
#> Sum_Squares_Total | Sum_Squares_Between | Sum_Squares_Within |    R2
#> --------------------------------------------------------------------
#> 681.371           |             602.519 |             78.851 | 0.884
# hclust
data <- iris[1:4]
model <- hclust(dist(data))
clusters <- cutree(model, 3)

rez <- cluster_performance(model, data, clusters)
rez
#> # Indices of model performance
#> 
#> Sum_Squares_Total | Sum_Squares_Between | Sum_Squares_Within |    R2
#> --------------------------------------------------------------------
#> 681.371           |             591.846 |             89.525 | 0.869
# DBSCAN
if (require("dbscan", quietly = TRUE)) {
  model <- dbscan::dbscan(iris[1:4], eps = 1.45, minPts = 10)

  rez <- cluster_performance(model, iris[1:4])
  rez
}
#> # Indices of model performance
#> 
#> Sum_Squares_Total | Sum_Squares_Between | Sum_Squares_Within |    R2
#> --------------------------------------------------------------------
#> 681.371           |             526.424 |            154.947 | 0.773
# Retrieve performance from parameters
params <- model_parameters(kmeans(iris[1:4], 3))
cluster_performance(params)
#> # Indices of model performance
#> 
#> Sum_Squares_Total | Sum_Squares_Between | Sum_Squares_Within |    R2
#> --------------------------------------------------------------------
#> 681.371           |             602.519 |             78.851 | 0.884