K-Means Clustering Algorithm

Machine Learning courses with 100+ Real-time projects Start Now!!

Program 1

from sklearn.cluster import KMeans
import pandas as pd

# Sample data
data = pd.DataFrame({
    "Income": [15000, 16000, 90000, 95000, 60000, 62000,65000,98000,12000],
    "SpendingScore": [90, 85, 20, 15, 50, 55,54,23,94]
})

# Apply K-Means
kmeans = KMeans(n_clusters=3, random_state=42) # This sets the number of clusters to 3.
data["Cluster"] = kmeans.fit_predict(data)
print(data)

You give me 15 seconds I promise you best tutorials
Please share your happy experience on Google

courses

DataFlair Team

DataFlair Team provides high-impact content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. We make complex concepts easy to grasp, helping learners of all levels succeed in their tech careers.

Leave a Reply

Your email address will not be published. Required fields are marked *