% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/semantic_analysis.R
\name{calculate_clustering_metrics}
\alias{calculate_clustering_metrics}
\title{Calculate Clustering Quality Metrics}
\usage{
calculate_clustering_metrics(
  clusters,
  data_matrix,
  dist_matrix = NULL,
  metrics = "all"
)
}
\arguments{
\item{clusters}{Integer vector of cluster assignments}

\item{data_matrix}{Numeric matrix of data points (rows = observations, cols = features)}

\item{dist_matrix}{Optional distance matrix. If NULL, computed from data_matrix}

\item{metrics}{Character vector of metrics to calculate.
Options: "silhouette", "davies_bouldin", "calinski_harabasz", or "all" (default)}
}
\value{
A named list containing:
\describe{
\item{silhouette}{Silhouette score (-1 to 1, higher is better)}
\item{davies_bouldin}{Davies-Bouldin index (lower is better)}
\item{calinski_harabasz}{Calinski-Harabasz index (higher is better)}
\item{n_clusters}{Number of clusters}
\item{cluster_sizes}{Table of cluster sizes}
}
}
\description{
Calculates common clustering evaluation metrics including Silhouette Score,
Davies-Bouldin Index, and Calinski-Harabasz Index.
}
\details{
\itemize{
\item Silhouette Score: Measures how similar an object is to its own cluster compared
to other clusters. Range: -1 to 1, higher is better.
\item Davies-Bouldin Index: Average similarity between each cluster and its most
similar cluster. Lower values indicate better clustering.
\item Calinski-Harabasz Index: Ratio of between-cluster to within-cluster variance.
Higher values indicate better-defined clusters.
}
}
\examples{
\donttest{
abstracts <- TextAnalysisR::SpecialEduTech$abstract[1:20]
term_matrix <- as.matrix(quanteda::dfm(quanteda::tokens(abstracts)))
kmeans_result <- stats::kmeans(term_matrix, centers = 2)
metrics <- calculate_clustering_metrics(kmeans_result$cluster, term_matrix)
print(metrics)
}
}
\concept{semantic}
