Skip to content
C

Problem 4: Visualize K-Means Clusters and Centroids

Easypython

Problem Description

Write a Python program that fits a K-Means model to a dataset and creates a scatter plot showing each cluster in a different color, with centroids marked distinctly.

Input

A 2D dataset with visually distinct groups.

Output

A displayed scatter plot with color-coded clusters and marked centroids.

Constraints

  • At least 6 points.

Example Input

text
[[2,3],[3,3],[2,4],[8,8],[9,8],[8,9]]

Example Output

text
(A scatter plot with two colors representing the two clusters, and red X marks for centroids)

Concepts Covered

KMeans, plt.scatter() with color coding.

Input (stdin)

Output

Run your code to see output here...