Welcome to Day-14 – Unsupervised Learning (K-Means Clustering)
Till now:
-
You had labeled data (
Pass = 0/1)
Today:
Model finds patterns WITHOUT labels 🤯
This is called: Unsupervised Learning
🎯 Goal of Day-14
You will:
✅ Understand clustering
✅ Learn K-Means algorithm
✅ Group similar data automatically
✅ Visualize clusters
🧠 What is Clustering?
Grouping similar data points together.
Example:
- Customers with similar spending habits
- Similar products
- Similar users
WITHOUT predefined labels.
🧠 Real-Life Examples
| Use Case | Example |
|---|---|
| E-commerce | Customer segmentation |
| Netflix | Similar viewers |
| Banking | Fraud pattern groups |
| Marketing | Target audience |
🧠 K-Means Concept
Algorithm tries to create:
K groups (clusters)
Example:
K = 2
Means: 2 clusters
🧠 Visual Idea
Think like:
📊 Customer Groups
import matplotlib.pyplot as plt
from sklearn.cluster import KMeans
Example:
- Study hours
- Marks
"Hours": [1,2,3,4,5,6,7,8],
"Marks": [40,42,50,54,70,78,90,95]
}
df = pd.DataFrame(data)
plt.xlabel("Hours")
plt.ylabel("Marks")
plt.title("Student Data")
plt.show()
plt.xlabel("Hours")
plt.ylabel("Marks")
plt.title("Student Data")
plt.show()
n_clusters=2,
random_state=42
)
df[["Hours", "Marks"]]
)
print(df)
df["Hours"],
df["Marks"],
c=df["Cluster"]
)
plt.xlabel("Hours")
plt.ylabel("Marks")
plt.title("K-Means Clustering")
plt.show()
🧠 What Happened?
Model automatically grouped:
- Similar students together
Without:
Pass / Fail labels
🚀 Part 7 – Cluster Centers
print(model.cluster_centers_)
These are:
center points of clusters
🧠 Key Difference
| Supervised Learning | Unsupervised Learning |
|---|
| Has labels | No labels |
| Predict output | Find hidden patterns |
| Example: Pass/Fail | Example: Customer groups |
🧠 Important Concept – Elbow Method
How to choose best K?
We use:
Elbow Method
(We’ll learn advanced version later.)
⚠ Important Interview Question
Q: What is unsupervised learning?
Answer:
A type of ML where models find hidden patterns in unlabeled data.
🧠 Real AI Insight
Clustering is heavily used in:
- Recommendation systems
- Fraud detection
- Market segmentation
- Behavioral analysis
🎯 End of Day-14 Goals
You now:
✅ Understand unsupervised learning
✅ Built clustering model
✅ Visualized clusters
0 Comments
If you have any queries, please let me know. Thanks.