50% off: Unlimited data and AI learning.
State of Data and AI Literacy Report 2025

AnimalSequences (version 0.2.0)

perform_clustering: Perform Various Clustering Methods

Description

This function performs multiple clustering methods on the input data and returns the results. The methods include K-means, hierarchical clustering, DBSCAN, Gaussian Mixture Model (GMM), spectral clustering, and affinity propagation.

Usage

perform_clustering(data, n_clusters = 3)

Value

A list with clustering results for each method:

kmeans

A list containing the results of K-means clustering, including cluster assignments.

hierarchical

A vector of cluster assignments from hierarchical clustering.

dbscan

A vector of cluster assignments from DBSCAN.

gmm

A vector of cluster assignments from Gaussian Mixture Model (GMM).

spectral

A vector of cluster assignments from spectral clustering.

affinity_propagation

A list of clusters from affinity propagation.

Arguments

data

A numeric matrix or data frame where rows represent observations and columns represent features.

n_clusters

An integer specifying the number of clusters for methods that require it (e.g., K-means, hierarchical clustering). Default is 3.

Details

- **K-means**: Performs K-means clustering with the specified number of clusters. - **Hierarchical clustering**: Performs hierarchical clustering and cuts the dendrogram to create the specified number of clusters. - **DBSCAN**: Applies DBSCAN clustering with predefined parameters. - **Gaussian Mixture Model (GMM)**: Uses the Mclust package to perform GMM clustering. - **Spectral clustering**: Uses the kernlab package to perform spectral clustering with a kernel matrix. - **Affinity propagation**: Uses the apcluster package to perform affinity propagation clustering.

Examples

Run this code
# Generate sample data
data <- matrix(rnorm(100), nrow = 10)

# Perform clustering
clustering_results <- perform_clustering(data, n_clusters = 3)

# Access the results
clustering_results$kmeans
clustering_results$hierarchical
clustering_results$dbscan
clustering_results$gmm
clustering_results$spectral
clustering_results$affinity_propagation

Run the code above in your browser using DataLab