Header Ads Widget

Responsive Advertisement

Ticker

6/recent/ticker-posts

Day-6 – Logistic Regression (Classification – Real-world ML)

Welcome to Day-6 – Logistic Regression (Classification)

🎯 Goal of Day-6

You will:

✅ Understand classification
✅ Build first classification model
✅ Predict YES/NO type output

🧠 What is Classification?

Instead of predicting numbers → we predict categories

Examples:

  • Spam / Not Spam 📧
  • Pass / Fail 🎓
  • Fraud / Not Fraud 💳

🧠 Logistic Regression Concept

Even though name says “regression”, it is used for classification.

It outputs probability (0 to 1):

Then converts to:

  • p > 0.5 → 1 (Yes)
  • p ≤ 0.5 → 0 (No)

🚀 Part 1 – Import Libraries

import pandas as pd
from sklearn.linear_model import LogisticRegression

🚀 Part 2 – Create Dataset

Example: Pass/Fail based on study hours

data = {
"Hours": [1, 2, 3, 4, 5, 6],
"Pass": [0, 0, 0, 1, 1, 1]
}

df = pd.DataFrame(data)


🚀 Part 3 – Prepare Data

X = df[["Hours"]]
y = df["Pass"]


🚀 Part 4 – Train Model

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


🚀 Part 5 – Predict

new_data = pd.DataFrame({"Hours": [3.5]})

prediction = model.predict(new_data)
print("Prediction:", prediction)

Output:

0 or 1


🚀 Part 6 – Probability (Very Important)

prob = model.predict_proba(new_data)
print(prob)


Example output:

[[0.7 0.3]]

Post a Comment

0 Comments