Sklearn KMeans icon

Sklearn KMeans

K-Means clustering using scikit-learn

Predict

AI-generated

Summary

Assign cluster labels to each input record using a previously fitted K-Means model.

Inputs

  • modelData (required) — JSON string containing the fitted model (cluster centers, etc.)
  • predictFeatureColumns (required) — Comma‑separated list of feature column names to use for prediction

Output shape

A list of items, each extending the original record with 'cluster' (predicted label) and 'distances_to_centers' (list of distances to cluster centers)

All input records are passed through; the returned list has the same length as the input.

Examples

Example 1: Predict clusters for a table of customer data using a stored K-Means model

modelData = '{"cluster_centers":[[...],...],"n_clusters":3,"feature_columns":["age","income"]}'
predictFeatureColumns = "age,income"

Discussion