Skip to main content

Posts

Showing posts from May, 2025

Mms

import numpy as np import matplotlib.pyplot as plt from sklearn.cluster import KMeans # Given dataset data = np.array([     [1.0, 2.0],     [1.5, 1.8],     [5.0, 8.0],     [8.0, 8.0],     [1.0, 0.6],     [9.0, 11.0],     [8.0, 2.0],     [10.0, 2.0],     [9.0, 3.0] ]) # Perform K-Means clustering with 3 clusters kmeans = KMeans(n_clusters=3, random_state=42) kmeans.fit(data) labels = kmeans.labels_ centroids = kmeans.cluster_centers_ # Visualize the clustered data points and centroids plt.figure(figsize=(8, 6)) colors = ['red', 'blue', 'green'] # Plot data points with cluster colors for i in range(len(data)):     plt.scatter(data[i, 0], data[i, 1], color=colors[labels[i]], s=100) # Plot centroids plt.scatter(centroids[:, 0], centroids[:, 1], marker='X', s=200, color='black', linewidths=2) # Add labels and title plt.title('K-Means Clustering Results', fontsize=14) plt.xlabel('X-axis', fonts...