For K-Means
# Import libraries
from sklearn.cluster import KMeans
import numpy as np

# Take number of data points
n = int(input("Enter number of data points: "))

# Take X and Y coordinates for each point
data = []
for i in range(n):
    x = float(input(f"Enter X value {i+1}: "))
    y = float(input(f"Enter Y value {i+1}: "))
    data.append([x, y])

# Convert to numpy array
X = np.array(data)

# Take number of clusters from user
k = int(input("Enter number of clusters (k): "))

# Create and fit K-Means model
kmeans = KMeans(n_clusters=k, random_state=42)
kmeans.fit(X)

# Get cluster centers and labels
centroids = kmeans.cluster_centers_
labels = kmeans.labels_

# Display results
print("\nCluster Centers (Centroids):")
print(centroids)
print("\nCluster Labels for each data point:")
for i in range(len(X)):
    print(f"Point {X[i]} → Cluster {labels[i]}")





