Learn R Programming

somhca (version 0.1.3)

clusterSOM: Perform Clustering on SOM Nodes

Description

Groups similar nodes of the SOM using hierarchical clustering and the KGS penalty function to determine the optimal number of clusters.

Usage

clusterSOM(model, plot_result = TRUE, file_path = NULL)

Value

A plot of the clusters on the SOM grid (if `plot_result = TRUE`). If `file_path` is specified, the clustered dataset is stored in a package environment for retrieval.

Arguments

model

The trained SOM model object.

plot_result

A logical value indicating whether to plot the clustering result. Default is `TRUE`.

file_path

An optional string specifying the path to a CSV file. If provided, clusters are assigned to the observations in the original dataset, and the updated data is stored in a package environment as 'DataAndClusters'.

Examples

Run this code
# Create a toy matrix with 9 columns and 100 rows
data <- matrix(rnorm(900), ncol = 9, nrow = 100)  # 900 random numbers, 100 rows, 9 columns

# Run the finalSOM function with the mock data
model <- finalSOM(data, dimension = 6, iterations = 700)

# Perform clustering using the mock model
clusterSOM(model, plot_result = TRUE)

# Load the toy data from the package's inst/extdata/ directory, perform
# clustering and retrieve the clustered dataset
file_path <- system.file("extdata", "toy_data.csv", package = "somhca")
clusterSOM(model, plot_result = FALSE, file_path)
getClusterData()

Run the code above in your browser using DataLab