# k-means with scikit-learn

scikit-learn's KMeans runs the whole k-means loop, with fit_predict giving each example a group number and cluster_centers\_ holding the centers, but its distances weigh features by their units, so the features are scaled first in a pipeline, several starts are run (n_init) with a fixed random_state, and the result suits round groups of similar spread.

![Cheat sheet: k-means with scikit-learn](https://fsdtrainingmedia.blob.core.windows.net/public/images/2026/11/c905cee7c63a47afb629879d712491cc.webp)

- Category: Machine Learning
- Level: Journeyman
- Tags: ai, fit_predict(), KMeans, k-means++, Pipeline (python), python, StandardScaler
- Author: Gregor Dzierzon
- Updated: November 23, 2026

Source: https://www.ask-codey.com/cheat-sheets/ml-k-means-with-scikit-learn-cheat-sheet
