K-means clustering
K-means clustering partitions data into a specified number of groups by assigning observations to representative centers and iteratively updating those centers to reduce within-group distances.
Data Without Labels
K-means clustering is an iterative clustering algorithm that partitions observations into a specified number of groups by minimizing within-group squared distance to cluster centroids.
- How it is used
- Uses k-means to group vehicle features and develop actionable customer segments without a target variable.
- How deep it goes
- Works through centroid reassignment and a Python workflow; defers detailed outlier treatment.
- Examples
- Uses vehicle features for a Python fit and customer transactions for business segmentation; suggests an iris comparison exercise.
- What you can do after
- Apply it via scikit-learn KMeans to standardized features, examine an elbow plot, and inspect centroids and cluster labels.
Advanced Algorithms and Data Structures
K-means is an iterative clustering algorithm that partitions observations into a specified number of clusters by minimizing within-cluster squared distances to cluster centroids.
- How it is used
- Partitions unlabeled points into a specified number of clusters, including for customer segmentation and constrained SS+-tree splits.
- How deep it goes
- Develops initialization, assignment, recentering, stopping, failure modes, pseudocode, complexity, and a distributed implementation.
- Examples
- Uses a three-centroid point diagram, an unlucky initialization, a constrained tree split, and customer segmentation.
- What you can do after
- Build it from scratch using assignment and recentering loops, then evaluate when its shape and dimensionality constraints make it suitable.
Read how Advanced Algorithms and Data Structures explains K-means clustering →
Statistics Slam Dunk
K-means is a clustering algorithm that partitions observations into a prespecified number of groups by minimizing within-group squared distances to cluster centroids.
- How it is used
- Segments observations into data-defined groups when analysis has input variables but no target variable.
- How deep it goes
- Explains iterative centroid assignment, convergence, K selection, R output, visualization, and distribution caveats without formal proofs.
- Examples
- Uses customer segmentation and NBA team payrolls with regular-season wins, visualized across candidate K values and a four-cluster solution.
- What you can do after
- Apply it via R’s kmeans function and factoextra visualizations to select K, segment observations, and inspect cluster results.
Classic Computer Science Problems in Swift: Essential techniques for practicing programmers
K-means clustering is an iterative unsupervised learning algorithm that partitions data points into a predefined number of clusters by repeatedly assigning points to their nearest centroid and recomputing the centroids.
- How it is used
- Uses clustering to reveal structure in data when little is known about its groupings.
- How deep it goes
- Works through normalization, random initialization, assignment, centroid updates, and stopping, then notes extensions without detailing them.
- Examples
- Demonstrates three-dimensional points and clusters state governors by longitude and age.
- What you can do after
- Build it from scratch in Swift by defining multidimensional points and iterating nearest-centroid assignments and mean updates.
The Well-Grounded Data Analyst
K-means is a clustering algorithm that partitions observations into a specified number of groups by minimizing distances from observations to their assigned cluster centers.
- How it is used
- Applies clustering to segment mobile users into actionable behavioral groups.
- How deep it goes
- Explains scaling, cluster-count selection, assignments, inertia, and center interpretation without mathematical derivation.
- Examples
- Uses mobile-user records, inertia plots, cluster counts, transformed features, cluster centers, and behavioral personas.
- What you can do after
- Apply it via scikit-learn to assign observations to clusters and interpret their behavioral profiles.
Read how The Well-Grounded Data Analyst explains K-means clustering →
Build AI-Enhanced Web Apps
K-means clustering is an unsupervised clustering algorithm that assigns data points to a chosen number of groups according to their distances from cluster centers.
- How it is used
- Improves long-document summarization by grouping semantically similar chunks before merging and summarizing them.
- How deep it goes
- Explains the full chunking, embedding, clustering, distance comparison, and merging pipeline, with a JavaScript implementation.
- Examples
- Uses document chunks, Hugging Face feature embeddings, ml-kmeans, similarity thresholds, and semantically coherent merged sections.
- What you can do after
- Build it from scratch as a JavaScript preprocessing stage for document summarization.
Read how Build AI-Enhanced Web Apps explains K-means clustering →
AI-Powered Search
K-means is an unsupervised clustering algorithm that partitions items into a specified number of groups by iteratively assigning items to and updating cluster centroids.
- How it is used
- Supports personalized search by converting product and query embeddings into dynamic categories for personalization guardrails.
- How deep it goes
- Provides Python fitting, labeling, visualization, and prediction, then recommends related top-N cosine clusters over a single assignment.
- Examples
- Uses product embeddings, cluster descriptions, visualized centroids, and the “microwave” query with five related predicted categories.
- What you can do after
- Apply it via Python and scikit-learn to generate categories and map queries to clusters for search personalization.
Related concepts
- centroiduses · A centroid is a central point representing a geometric figure or set of points, commonly calculated as the coordinate-wise mean, with weights when applicable.
- Euclidean distanceuses · Euclidean distance is the straight-line distance between two points in Euclidean space, calculated as the square root of the sum of squared differences between corresponding coordinates.
- clusteringproduces · Clustering is the technique of grouping data items according to similarity or shared characteristics.
- hierarchical clusteringcontrasts with · Hierarchical clustering is a clustering method that organizes observations into nested groups by successively merging or splitting clusters.
- unsupervised learningkind of · Unsupervised learning is a machine-learning approach that discovers patterns, structure, or representations in data without labeled target outputs.
- hard clusteringkind of · Hard clustering assigns each observation to at most one cluster, with all clusters represented at the same hierarchy level.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.






