% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/gmeans.R
\name{compute_wss}
\alias{compute_wss}
\title{Compute Within-Cluster Sum of Squares}
\usage{
compute_wss(object, newdata = NULL)
}
\arguments{
\item{object}{(\code{any})\cr
Class inheriting from \code{"kmeans"}.}

\item{newdata}{(\code{matrix()})\cr
New data to predict on.}
}
\value{
A \code{numeric()} vector with one within-cluster sum of squares per cluster,
in the order of the rows of \code{object$centers}. Clusters with no assigned points
contribute \code{0}.
}
\description{
Compute Within-Cluster Sum of Squares
}
\details{
WSS is defined as \deqn{
  \sum_{i=1}^{n} \left\|x_{i} - \mu_{j(i)}\right\|^2,
}
where \eqn{x_{i}} is a data point and \eqn{\mu_{j(i)}} is the centroid of the cluster
to which \eqn{x_{i}} is assigned. When new data is provided, the function predicts
the nearest cluster for each new observation and computes the WSS for these points
based on their predicted clusters.
}
\examples{
km <- kmeans(mtcars, 5)
compute_wss(km)
# or with new data
compute_wss(km, mtcars)
}
