📊 Model Evaluation Metrics (Accuracy, F1, ROC AUC)
Machine Learning में केवल model train करना ही काफी नहीं होता। असली value तब आती है जब हम model को सही तरीके से evaluate करें। Model evaluation metrics हमें यह समझने में मदद करते हैं कि हमारा model कितना अच्छा काम कर रहा है, किन scenarios में fail हो सकता है और business goals को कितना achieve कर पा रहा है।
🔍 Model Evaluation Metrics क्यों ज़रूरी हैं?
- सिर्फ Accuracy देखकर misclassification errors को ignore नहीं किया जा सकता।
- हर dataset में class imbalance हो सकता है, जिसे different metrics highlight करते हैं।
- Business use case के अनुसार metric का चयन बदल सकता है (जैसे medical diagnosis में recall ज़्यादा important है)।
- Evaluation metrics model selection और hyperparameter tuning में crucial role निभाते हैं।
✅ Confusion Matrix – Foundation of Metrics
Confusion Matrix एक 2x2 table है जो classification problems के लिए बहुत useful है:
- True Positive (TP): Positive case सही predict हुआ।
- False Positive (FP): Negative case को positive predict कर दिया।
- True Negative (TN): Negative case सही predict हुआ।
- False Negative (FN): Positive case को negative predict कर दिया।
🎯 Accuracy
Accuracy = (TP + TN) / (TP + TN + FP + FN)
यह बताता है कि total predictions में से कितने correct थे। लेकिन class imbalance वाले datasets में accuracy misleading हो सकती है।
🎯 Precision
Precision = TP / (TP + FP)
यह बताता है कि model द्वारा predict किए गए positives में से कितने सही थे। Fraud detection जैसे use cases में precision critical है।
🎯 Recall (Sensitivity)
Recall = TP / (TP + FN)
यह बताता है कि actual positives में से कितने model ने detect किए। Medical diagnosis जैसे areas में recall बहुत महत्वपूर्ण है।
🎯 F1-Score
F1 = 2 * (Precision * Recall) / (Precision + Recall)
F1-score precision और recall का harmonic mean है। यह तब useful है जब precision और recall दोनों ही important हों।
🎯 ROC Curve & AUC
ROC Curve एक graphical representation है जिसमें x-axis पर False Positive Rate और y-axis पर True Positive Rate plot किया जाता है।
AUC (Area Under Curve) बताता है कि model कितनी अच्छी तरह से classes को अलग कर पा रहा है। AUC = 1 perfect model को represent करता है।
📌 Example: Metrics in Python
from sklearn.metrics import accuracy_score, precision_score, recall_score, f1_score, roc_auc_score y_true = [0, 1, 1, 0, 1, 0, 1] y_pred = [0, 1, 0, 0, 1, 0, 1] print("Accuracy:", accuracy_score(y_true, y_pred)) print("Precision:", precision_score(y_true, y_pred)) print("Recall:", recall_score(y_true, y_pred)) print("F1 Score:", f1_score(y_true, y_pred)) print("ROC AUC:", roc_auc_score(y_true, y_pred))
✅ Best Practices
- Imbalanced datasets में सिर्फ accuracy पर depend न करें।
- Business problem के हिसाब से सही metric चुनें।
- Precision-recall trade-off को हमेशा ध्यान में रखें।
- Multiple metrics का उपयोग करें holistic evaluation के लिए।
- Cross-validation metrics ज़्यादा reliable results देते हैं।
निष्कर्ष यह है कि Model Evaluation Metrics किसी भी Machine Learning pipeline की backbone हैं। Accuracy basic overview देती है, जबकि Precision, Recall और F1-score detailed understanding देते हैं। ROC-AUC हमें probabilistic separation की ताकत बताता है। सही metric चुनना ही एक successful AI project की key है।