A company wants to group customer records into clusters based on two numerical behavioral features. Since the records are not labeled, use K-Means clustering to create the groups. Generate a synthetic dataset using scikit-learn and group its data points using the number of clusters provided as input.
Dataset Generation:
Generate the dataset using:
from sklearn.datasets import make_blobs
Use the following fixed parameters:
n_samples=300centers=4n_features=2random_state=0Task:
Write a Python program that performs the following steps:
Generate the synthetic dataset using the specified parameters.
Read two integers from standard input:
n_clusters
random_state
Initialize a K-Means model using:
n_clusters equal to the input value
random_state equal to the input value
n_init=10
Train the K-Means model using the generated dataset.
Count the number of data points in every cluster.
Sort the cluster sizes in ascending order.
Print each sorted cluster size on a separate line.
Constraints: 2 <= n_clusters <= 6 0 <= random_state <= 10000
Input Format:
Two space-separated integers:
<n_clusters><space><random_state>
Output Format:
Print n_clusters lines.
Each line must contain one cluster size. The sizes must be printed in ascending order.
Sample Input 1:
4 0
Sample Output 1:
74
74
75
77
Note: Cluster label numbers can vary internally. Therefore, print only the sorted cluster sizes. Do not print any extra text or labels.
BNY • Pending