Header Ads Widget

Responsive Advertisement

Ticker

6/recent/ticker-posts

Day-9 – Model Evaluation

🎯 Goal of Day-9

You will:

✅ Measure model performance
✅ Understand accuracy
✅ Learn precision & recall

✅ Use confusion matrix 


🧠 Why Evaluation Matters

Imagine:

  • Model predicts → Pass/Fail
  • But is it correct? ❓

Without evaluation:
👉 Model = useless


🚀 Part 1 – Import Metrics

from sklearn.metrics import accuracy_score, confusion_matrix, classification_report


🚀 Part 2 – Create Dataset

import pandas as pd

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

df = pd.DataFrame(data)

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


🚀 Part 3 – Train Model

from sklearn.linear_model import LogisticRegression

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


🚀 Part 4 – Predictions

y_pred = model.predict(X)


🚀 Part 5 – Accuracy

accuracy = accuracy_score(y, y_pred)
print("Accuracy:", accuracy)


🧠 Accuracy Formula

👉 Example:

  • 8 correct out of 10 → 80%

🚀 Part 6 – Confusion Matrix

cm = confusion_matrix(y, y_pred)
print(cm)

Example output:

[[3 1]
[0 4]]

🧠 Confusion Matrix Meaning

                           Predicted 0      Predicted 1
Actual 0                           True Neg      False Pos
Actual 1                           False Neg      True Pos 


👉 This is VERY important for interviews.

🚀 Part 7 – Precision & Recall

report = classification_report(y, y_pred)
print(report)

🧠 Key Metrics

🔹 Precision

Out of predicted YES, how many are correct?

🔹 Recall

Out of actual YES, how many did we catch?


🎯 Real-Life Example

Spam Detection:

  • Precision → Don’t mark important mail as spam
  • Recall → Catch all spam

👉 Trade-off depends on use case. 


🧠 Real AI Insight

  • Accuracy is not enough
  • Always check:
    • Precision
    • Recall
    • Confusion matrix

🎯 End of Day-9 Goals

You now:

✅ Evaluate ML models
✅ Understand accuracy
✅ Understand precision/recall
✅ Compare models


Github link : https://github.com/dotnetfullstackdeveloper/ai-engineer-journey/blob/main/Week-02-Machine-Learning/Day-9%20%E2%80%93%20Model%20Evaluation

Post a Comment

0 Comments