الـ Confusion Matrix والـ Precision والـ Recall والـ F1 Score
الـ confusion matrix بتعد التوقعات الصح والغلط لكل class، والـ precision والـ recall والـ F1 بيتحسبوا من الـ true/false positives وnegatives.
في الـ binary confusion matrix كل صف (row) هو الـ actual class وكل عمود (column) هو الـ predicted class (في Scikit-Learn). الخانات الأربعة: true positives (TP) وfalse positives (FP) وtrue negatives (TN) وfalse negatives (FN). الـ classifier المثالي مصفوفته فيها قيم بس على القطر الرئيسي.
الـ Precision = TP / (TP + FP): من كل اللي توقعناه positive كام فعلًا positive. الـ Recall (أو sensitivity أو TPR) = TP / (TP + FN): من كل الـ positives الحقيقية كام لقينا. الـ Specificity = TN / (TN + FP). الـ Accuracy = (TP + TN) / الكل.
الـ F1 هو الـ harmonic mean بين precision وrecall: F1 = 2 × precision × recall / (precision + recall). عشان harmonic mean مبيبقاش عالي إلا لو الاتنين عاليين. الـ precision والـ recall بيتعاكسوا: لما ترفع الـ threshold الـ precision بتزيد والـ recall بتقل والعكس. ده الـ precision/recall trade-off.
أهم النقاط
- Precision = TP/(TP+FP) وrecall = TP/(TP+FN).
- الـ F1 هو harmonic mean بين precision وrecall.
- زيادة الـ precision غالبًا بتقلل الـ recall.
- الـ accuracy ممكن تضلل لو الـ classes مش متوازنة، والـ confusion matrix أحسن.
- Specificity = TN/(TN+FP) والـ error rate = 1 - accuracy.
مثال محلول
اختبار سرطان طلع TP=40 وFP=10 وFN=20 وTN=930. Precision = 40/50 = 0.80. Recall = 40/60 = 0.67. F1 = 2 × 0.80 × 0.67 / 1.47 = 0.73. Accuracy = 970/1000 = 0.97 وده بيخبّي إن 20 مريض اتفوتوا.
أسئلة شائعة
إيه الفرق بين precision وrecall؟
الـ precision بتسأل من اللي توقعناهم positive كام صح. الـ recall بتسأل من الـ positives الحقيقية كام لقينا.
ليه F1 بيستخدم harmonic mean؟
لأنه بيعاقب الفرق الكبير بين precision وrecall، فمبيبقاش عالي إلا لو الاتنين عاليين.
أسئلة تدريب على الموضوع ده
جرّبها بنفسك، وبعدين افتح التطبيق وشوف الإجابة والشرح.
- ................is the inverse precision.
- A. Negative Predictive Value
- B. Positive Prediction Value
- C. True Negative Rate
- D. none of them
- the combination of precision and recall into a single metric called confusion matrix
- A. false
- B. true
- The higher the recall (TPR), the more false positives (FPR) the classifier produces.
- A. true
- B. false
- Increasing precision reduces recall, and vice versa. This is called the precision/recall trade-off
- A. true
- B. false
- What is the purpose of a confusion matrix?
- A. To evaluate the performance of a classification algorithm
- B. To identify the most important features in a dataset
- C. To select the right machine learning algorithm for a given problem
- D. To tune the hyperparameters of a machine learning algorithm
- the confusion matrix of perfect classifier would have ............. values only on its main diagonal
- A. nonzero
- B. zero
- C. ones
- D. none of them
مواضيع مرتبطة
- شرح الـ ROC Curve والـ AUC
- الـ K-Fold والـ Stratified K-Fold Cross-Validation
- الـ Multiclass Classification: One-versus-One و One-versus-Rest
- شرح داتا MNIST والـ SGDClassifier
- يعني إيه Machine Learning؟
- الفرق بين Supervised و Unsupervised و Semi-supervised و Reinforcement Learning
- كل المواضيع: الماشين ليرنينج
بصمجلي مشروع طلابي مستقل، مش موقع رسمي لجامعة الدلتا. ارجع لمحاضراتك ودكتورك دايمًا.