TGViewer
Artificial Intelligence Artificial Intelligence @machinelearning_deeplearning · 56.3K subscribers
Post #1737 4.18K
✅ Supervised vs Unsupervised Learning 🤖📚

Let’s explore these two core types of machine learning in detail and how you can apply them using Python and Scikit-learn.

1️⃣ Supervised Learning
Supervised learning means the model learns from data where both input and the correct output are provided. You "supervise" the model with answers.

For example, you give it house size and price, and it learns to predict the price for a new house.

Key use cases:
• Predicting house prices
• Classifying emails as spam or not
• Recognizing handwritten digits

Supervised learning includes two types:
• Classification – Output is a category (e.g., dog or cat)
• Regression – Output is a number (e.g., price, age)

Example: Classification using Iris dataset
from sklearn.datasets import load_iris  
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestClassifier

iris = load_iris()
X = iris.data
y = iris.target

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)

model = RandomForestClassifier()
model.fit(X_train, y_train)

accuracy = model.score(X_test, y_test)
print("Model Accuracy:", accuracy)


Example: Regression using California housing data
from sklearn.linear_model import LinearRegression  
from sklearn.datasets import fetch_california_housing

data = fetch_california_housing()
X = data.data
y = data.target

model = LinearRegression()
model.fit(X, y)

prediction = model.predict([X[0]])
print("Predicted price:", prediction)


2️⃣ Unsupervised Learning
In unsupervised learning, you give the model *only inputs*, without telling it what the correct output should be. The model tries to find patterns or groupings on its own.

Key use cases:
• Segmenting customers into groups
• Finding hidden patterns in data
• Reducing high-dimensional data for visualization

Main types:
• Clustering – Group similar items
• Dimensionality Reduction – Simplify data while keeping meaning

Example: Clustering using KMeans
from sklearn.cluster import KMeans  
from sklearn.datasets import make_blobs
import matplotlib.pyplot as plt

X, _ = make_blobs(n_samples=300, centers=3)

kmeans = KMeans(n_clusters=3)
kmeans.fit(X)

plt.scatter(X[:, 0], X[:, 1], c=kmeans.labels_)
plt.title("KMeans Clustering")
plt.show()


Key Differences
In supervised learning:
• You teach the model using examples with answers
• It predicts labels or numbers
• It's used for tasks like price prediction, image recognition

In unsupervised learning:
• You give the model raw data without answers
• It discovers patterns or groups
• It's used for things like customer segmentation

Pro Tip:
Use Scikit-learn’s built-in datasets to explore both types. Try changing the model or parameters and see how outputs change!

💬 Tap ❤️ for more!
  • ❤ 10
  • 👍 1
  • 🔥 1
More from @machinelearning_deeplearning
  1. Sep 22, 2026🚀 Welcome back to our AI Engineer Roadmap! ❤️ In the previous posts, we learned about fun…
  2. Sep 21, 2026🚀 Welcome back to our AI Engineer Roadmap! ❤️ In the previous post, we explored functions…
  3. Sep 20, 2026In the previous post, we learned how conditional statements allow Python programs to make…
  4. Sep 19, 2026In the previous post, we explored Python operators and even tested ourselves with some tri…
  5. Sep 18, 2026In the previous post, we learned how to convert one data type into another using Type Cast…
  6. Sep 17, 2026In the previous post, we learned how to take input from users and display output. One impo…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →