Ravindra BagaleCourses & study guides English Track your progress

36. K-Means Clustering — Python मध्ये

Data Science

36.1 Labels शिवाय गट

का गरजेचे आहे. कधी label column नसतो. Marketing तरी विचारते: “Pune customers चे काही behaviour buckets करता येतील का?” ते clustering — unsupervised learning (Chapter 29).

हे काय आहे. K-Means K centres ठेवते आणि प्रत्येक row जवळच्या centre ला assign करते. K तुम्ही निवडता. Accuracy साठी y नाही — groups business साठी उपयुक्त आहेत का हे तुम्ही ठरवता.

कसे करायचे.

Unsupervised प्रश्न तयार करा

  1. Numeric behaviour columns लिहा (orders_per_month, avg_basket_inr).
  2. मान्य करा: “योग्य group” column नसतो.
  3. Clusters पाहिल्यानंतर नावे ठेवायची योजना करा (उदा. “light”, “regular”, “bulk”).
import pandas as pd

cust = pd.DataFrame({
 "orders_per_month": [1, 2, 8, 9, 3, 12],
 "avg_basket_inr": [200, 250, 900, 950, 300, 1200],
 "city": ["Pune", "Nashik", "Pune", "Mumbai", "Kolhapur", "Pune"],
})
print(cust[["orders_per_month", "avg_basket_inr"]])
print("No churn label here — only groups.")

Ravindra Bagale's Tip

Clustering does not predict a known answer (y), because the data has no labels. It only finds groups of similar rows. In interviews, clearly explain the difference between supervised learning (with labels) and unsupervised learning (without labels).