🎯 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%
print(cm)
[0 4]]
| Predicted 0 | Predicted 1 | |
|---|---|---|
| Actual 0 | True Neg | False Pos |
| Actual 1 | False Neg | True Pos |
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
0 Comments
If you have any queries, please let me know. Thanks.