knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

Load kmeaningfulR library

library(kmeaningfulR)

Example array with 6 rows and 2 columns

X  <- array(c(0, 1, 10, 10, 10, 10, 0, 1, 10, 11, 0, 1), dim = c(6,2))
X

Scale data

X_scaled <- preprocess(X)
X_scaled

Find optimal number of clusters

optimal_K <- find_elbow(X_scaled)
optimal_K

Find cluster centers and label of nearest center to every point

assign_list <- fit_assign(X_scaled, optimal_K)
centers <- assign_list[[1]]
labels <- assign_list[[2]]
assign_list

Plot a 2D PCA visualisation of the points clusters

show_clusters(X_scaled, labels, centers)


UBC-MDS/kmeaningfulR documentation built on March 29, 2021, 7:55 a.m.