рдЕрдм рд╣рдо Deep Learning рдореЗрдВ рд╕рдмрд╕реЗ рдЬрд╝рд░реВрд░реА рдФрд░ рдЬрд╝реНрдпрд╛рджрд╛ рдЗрд╕реНрддреЗрдорд╛рд▓ рд╣реЛрдиреЗ рд╡рд╛рд▓реЗ Evaluation Metrics тАФ рд╡рд┐рд╢реЗрд╖рдХрд░ Confusion Matrix, Precision, рдФрд░ Recall тАФ рдХреЛ рдкреВрд░реА рдЧрд╣рд░рд╛рдИ рд╕реЗ рд╕рдордЭреЗрдВрдЧреЗред
ЁЯФ╖ 1. What Are Evaluation Metrics?
Evaluation metrics рдпрд╣ рдорд╛рдкрдиреЗ рдХреЗ рд▓рд┐рдП рд╣реЛрддреЗ рд╣реИрдВ рдХрд┐ trained model рдХрд┐рддрдиреА рд╕рд╣реА predictions рдХрд░ рдкрд╛ рд░рд╣рд╛ рд╣реИ тАФ рдЦрд╛рд╕рдХрд░ classification problems рдореЗрдВред
ЁЯФ╢ 2. Confusion Matrix (рдЧрдбрд╝рдмрдбрд╝реА рдореИрдЯреНрд░рд┐рдХреНрд╕)
Confusion matrix classification prediction рдХреЛ рдЪрд╛рд░ рд╣рд┐рд╕реНрд╕реЛрдВ рдореЗрдВ рддреЛрдбрд╝рддрд╛ рд╣реИ:
Predicted Positive | Predicted Negative | |
---|---|---|
Actual Positive (1) | тЬЕ TP (True Positive) | тЭМ FN (False Negative) |
Actual Negative (0) | тЭМ FP (False Positive) | тЬЕ TN (True Negative) |
ЁЯдЦ рдпреЗ matrix binary рдФрд░ multi-class рджреЛрдиреЛрдВ рдореЗрдВ рдХрд╛рдо рдХрд░рддрд╛ рд╣реИред
тЬЕ Python Code (PyTorch compatible)
from sklearn.metrics import confusion_matrix
y_true = [0, 1, 0, 1, 1, 0] # Ground truth
y_pred = [0, 1, 1, 1, 0, 0] # Model predictions
cm = confusion_matrix(y_true, y_pred)
print("Confusion Matrix:\n", cm)
Output:
[[2 1]
[1 2]]
рдпрд╣ рдХрд╣рддрд╛ рд╣реИ:
- 2 True Negatives (class 0 рд╕рд╣реА predict рдХрд┐рдпрд╛)
- 1 False Positive
- 1 False Negative
- 2 True Positives
ЁЯФ╢ 3. Precision (рд╕рдЯреАрдХрддрд╛)
Definition:
Model рдиреЗ рдЬрд┐рддрдиреЗ positive predict рдХрд┐рдП, рдЙрдирдореЗрдВ рд╕реЗ рдХрд┐рддрдиреЗ рд╕рдЪ рдореЗрдВ positive рдереЗ?
Precision = TP / (TP + FP)
тЬЕ Example:
Model рдиреЗ 10 images рдХреЛ “cat” рдХрд╣рд╛, рдкрд░ рдХреЗрд╡рд▓ 6 рд╣реА рдЕрд╕рд▓реА cat рдереАрдВ тЖТPrecision = 6 / 10 = 0.60
тЬЕ Code:
from sklearn.metrics import precision_score
precision = precision_score(y_true, y_pred)
print("Precision:", precision)
ЁЯФ╢ 4. Recall (Sensitivity / True Positive Rate)
Definition:
Total actual positive samples рдореЗрдВ рд╕реЗ рдХрд┐рддрдиреЛрдВ рдХреЛ model рдиреЗ рд╕рд╣реА predict рдХрд┐рдпрд╛?
Recall = TP / (TP + FN)
тЬЕ Example:
10 рдореЗрдВ рд╕реЗ 8 рдЕрд╕рд▓реА cats рдереАрдВ, рдФрд░ model рдиреЗ 6 рдХреЛ correctly рдкрдХрдбрд╝рд╛ тЖТRecall = 6 / 8 = 0.75
тЬЕ Code:
from sklearn.metrics import recall_score
recall = recall_score(y_true, y_pred)
print("Recall:", recall)
ЁЯФ╢ 5. F1 Score (Precision + Recall рдХрд╛ Balance)
Definition:
Precision рдФрд░ Recall рдХрд╛ harmonic mean:
F1 = 2 * (Precision * Recall) / (Precision + Recall)
тЬЕ Code:
from sklearn.metrics import f1_score
f1 = f1_score(y_true, y_pred)
print("F1 Score:", f1)
ЁЯФ╖ ЁЯФН Visualization (Optional)
import seaborn as sns
import matplotlib.pyplot as plt
sns.heatmap(cm, annot=True, fmt='d', cmap='Blues')
plt.xlabel("Predicted")
plt.ylabel("Actual")
plt.title("Confusion Matrix")
plt.show()
ЁЯза рдХрдм рдХреНрдпрд╛ Use рдХрд░реЗрдВ?
Metric | Use When… |
---|---|
Accuracy | Data balanced рд╣реЛ |
Precision | False Positive рд╕реЗ рдмрдЪрдирд╛ рдЬрд╝рд░реВрд░реА рд╣реЛ (e.g. spam) |
Recall | False Negative рд╕реЗ рдмрдЪрдирд╛ рдЬрд╝рд░реВрд░реА рд╣реЛ (e.g. cancer detection) |
F1 Score | Precision рдФрд░ Recall рджреЛрдиреЛрдВ рдЬрд╝рд░реВрд░реА рд╣реЛрдВ |
ЁЯУЭ Objective Questions:
- Confusion matrix рдХреЗ 4 parts рдХреНрдпрд╛ рд╣реЛрддреЗ рд╣реИрдВ?
- Precision рдФрд░ Recall рдореЗрдВ рдЕрдВрддрд░ рдХреНрдпрд╛ рд╣реИ?
- Precision рдХрдм рдЬрд╝реНрдпрд╛рджрд╛ important рд╣реЛрддрд╛ рд╣реИ?
f1_score
metric рдХрдм use рдХрд░рддреЗ рд╣реИрдВ?- Confusion matrix рдХрд╛ visualization рдХреИрд╕реЗ рдХрд░реЗрдВ?
ЁЯФЪ Summary
Metric | Formula | Meaning |
---|---|---|
Precision | TP / (TP + FP) | Predicted Positives рдореЗрдВ рд╕реЗ рд╕рд╣реА рдХрд┐рддрдиреЗ |
Recall | TP / (TP + FN) | Actual Positives рдореЗрдВ рд╕реЗ рд╕рд╣реА рдХрд┐рддрдиреЗ |
F1 Score | Harmonic mean of P & R | Balance of both metrics |
Confusion Matrix | TP, FP, FN, TN | Overall prediction structure |