تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
قدّم القسم السابق مجموعة من مقاييس النماذج، تم احتسابها جميعًا عند قيمة
حدّ تصنيف واحد. ولكن إذا كنت تريد تقييم
جودة النموذج على جميع الحدود الممكنة، ستحتاج إلى أدوات مختلفة.
منحنى الخصائص التشغيلية للمستقبِل (ROC)
منحنى ROC
هو تمثيل مرئي لأداء النموذج في جميع العتبات.
إنّ النسخة الطويلة من الاسم، وهي خاصية تشغيل جهاز الاستقبال، هي بقايا
من تكنولوجيا رصد الرادار في الحرب العالمية الثانية.
يتم رسم منحنى ROC من خلال احتساب معدّل الموجب الصحيح (TPR)
ومعدّل الموجب الخاطئ (FPR) عند كل حدّ ممكن (في الممارسة العملية، عند
فواصل زمنية محدّدة)، ثمّ رسم معدّل الموجب الصحيح على معدّل الموجب الخاطئ. يمكن تمثيل نموذج مثالي،
الذي يحقّق نسبة إيجابية حقيقية تبلغ 1.0 ونسبة خطأ إيجابية تبلغ 0.0 عند حدّ معيّن،
بنقطة عند
(0, 1) في حال تجاهل جميع الحدود الأخرى، أو بما يلي:
الشكل 1. منحنى خاصية تشغيل جهاز الاستقبال ومساحة تحت منحنى الأداء لنموذج مثالي افتراضي
المساحة تحت المنحنى (AUC)
تمثل المنطقة تحت منحنى ROC (AUC)
احتمالية أن يصنّف النموذج المثال الموجب على أنّه أعلى من المثال السلبي، إذا تم تقديم مثال موجب ومثال سلبي تم اختيارهما عشوائيًا.
النموذج المثالي أعلاه الذي يحتوي على مربّع أضلاعه بطول 1 له
مساحة تحت المنحنى (AUC) تبلغ 1.0. وهذا يعني أنّ هناك احتمالية بنسبة% 100 أن يصنّف النموذج بشكل صحيح مثالاً إيجابيًا تم اختياره عشوائيًا أعلى من مثال سلبي تم اختياره عشوائيًا. بعبارة أخرى، عند الاطّلاع على انتشار نقاط data أدناه، يقدّم مقياس AUC احتمالية أن يضع النموذج مربعًا تم اختياره عشوائيًا على يسار دائرة تم اختيارها عشوائيًا، بغض النظر عن مكان ضبط الحدّ الأدنى.
بعبارة أكثر تحديدًا، يحدِّد نظام تصنيف الرسائل غير المرغوب فيها الذي يمتلك AUC
1.0 دائمًا احتمالية أعلى بأن تكون رسالة إلكترونية عشوائية غير مرغوب فيها
غير مرغوب فيها مقارنةً برسالة إلكترونية عشوائية صالحة. يعتمد التصنيف الفعلي لكل بريد إلكتروني على الحدّ الأدنى الذي تختاره.
بالنسبة إلى المصنّف الثنائي، يُعدّ النموذج الذي يحقّق أداءً مماثلاً تمامًا للتوقّعات العشوائية أو
رمي العملات المعدنية هو نموذج ROC الذي يمثّل خطًا قطريًا من (0,0) إلى (1,1). تكون دالة AUC هي
0.5، ما يمثّل احتمالية بنسبة% 50 لترتيب مثال إيجابي و
سلبي عشوائي بشكل صحيح.
في مثال معرّف الرسائل غير المرغوب فيها، يحدِّد معرّف الرسائل غير المرغوب فيها الذي يبلغ AUC 0.5 احتمالية أعلى بأن تكون رسائل إلكترونية عشوائية غير مرغوب فيها مقارنةً برسائل إلكترونية عشوائية مرغوب فيها في نصف الوقت فقط.
الشكل 2. منحنى ROC وAUC للتخمينات العشوائية تمامًا
(اختياري ومتقدّم) منحنى الدقة والاستذكار
يعمل مقياسا AUC وROC بشكل جيد لمقارنة النماذج عندما تكون مجموعة البيانات متوازنة تقريبًا بين الفئات. عندما تكون مجموعة البيانات غير متوازنة، قد تقدّم منحنيات الدقة-الاسترجاع (PRC) والمساحة تحت هذه المنحنيات تمثيلاً مرئيًا مقارنةً
أفضل لأداء النموذج. يتم إنشاء منحنيات الدقة والتذكر من خلال
رسم الدقة على المحور y وتذكر على المحور x على مستوى كل
الحدود الدنيا.
AUC وROC لاختيار النموذج والحدّ الأدنى
يُعدّ مقياس AUC مقياسًا مفيدًا لمقارنة أداء نموذجَين مختلفَين،
ما دامت مجموعة البيانات متوازنة تقريبًا. بشكل عام، يكون النموذج الذي يضم مساحة أكبر تحت
المنحنى هو الأفضل.
الشكل 3. منحنى ROC ومساحة تحت منحنى ROC لنموذجَين افتراضيَين يمثّل المنحنى على
اليسار، الذي يضمّ مؤشرًا أكبر لمنطقة تحت منحنى ROC، أفضل هذين النموذجَين.
تمثّل النقاط على منحنى ROC الأقرب إلى (0,1) نطاقًا من
الحدود الدنيا الأفضل أداءً للنموذج المحدّد. كما هو موضّح في أقسام
الحدود الدنيا،
مصفوفة الالتباس
و
اختيار المقياس والمفاضلات
، يعتمد الحدّ الأدنى الذي تختاره على المقياس الأكثر أهمية لحالة الاستخدام المحدّدة. فكِّر في النقاط "أ" و"ب" و"ج" في الرسم البياني التالي، والتي تمثّل كلٌّ منها حدًا:
الشكل 4. ثلاث نقاط مصنّفة تمثّل الحدود الدنيا
إذا كانت النتائج الإيجابية الخاطئة (الإشعارات الخاطئة) باهظة التكلفة، قد يكون من المنطقي
اختيار حدّ يقدّم معدّل خطأ إيجابي أقلّ، مثل المعدّل في النقطة "أ"، حتى إذا تم خفض TPR. في المقابل، إذا كانت النتائج الموجبة الخاطئة منخفضة التكلفة والنتائج السالبة الخاطئة
(النتائج الموجبة الصائبة الفائتة) مرتفعة التكلفة، قد يكون الحدّ الأدنى للنقطة "ج"، الذي
يحقّق الحد الأقصى لنسبة النتائج الموجبة الصائبة، هو الخيار المفضّل. إذا كانت التكاليف متكافئة تقريبًا، قد تقدّم النقطة ب
أفضل توازن بين معدّل الإحالات الناجحة النسبي ومعدّل الإحالات الناجحة الإجمالي.
في ما يلي منحنى ROC للبيانات التي سبق أن رأيناها:
تمرين: التحقّق من فهمك
في الممارسة العملية، تكون منحنيات ROC أقل انتظامًا بكثير من الرسومات التوضيحية
الواردة أعلاه. أيٌّ من النماذج التالية، التي يمثّلها منحنى ROC
ومعامل AUC، يحقّق أفضل أداء؟
يحقّق هذا النموذج أعلى قيمة لمقياس AUC، ما يتوافق مع أفضل
أداء.
أيّ من النماذج التالية يحقّق أداءً أسوأ من الصدفة؟
يُظهر هذا النموذج قيمة AUC أقل من 0.5، ما يعني أنّ أدائه
أسوأ من الصدفة.
يحقّق هذا النموذج أداءً أفضل قليلاً من الصدفة.
يحقّق هذا النموذج الأداء نفسه الذي يحقّقه الاختيار العشوائي.
هذا هو تصنيف مثالي افتراضي.
(اختياري ومتقدّم) سؤال إضافي
أيّ من التغييرات التالية يمكن إجراؤها على نموذج "الأداء أسوأ من الصدفة"
في السؤال السابق لتحسين أدائه؟
اقلب التوقعات، بحيث تصبح التوقعات التي تبلغ 10، والتوقعات التي تبلغ 01.
إذا كان المصنّف الثنائي يضع الأمثلة في
الفئات الخاطئة بشكل موثوق أكثر من الصدفة، يؤدي تبديل تصنيف الفئة
على الفور إلى تحسين توقّعاته عن الصدفة بدون الحاجة إلى
إعادة تدريب النموذج.
اطلب من النموذج أن يتوقّع دائمًا الفئة السلبية.
وقد يؤدي ذلك إلى تحسين الأداء أو لا يؤدي إلى ذلك. بالإضافة إلى ذلك، كما هو موضح في قسم الدقة،
هذا النموذج ليس مفيدًا.
اطلب منه توقّع الفئة الموجبة دائمًا.
وقد يؤدي ذلك إلى تحسين الأداء أو لا يؤدي إلى ذلك. بالإضافة إلى ذلك، كما هو موضح في قسم الدقة،
ليس هذا النموذج مفيدًا.
تخيل موقفًا يكون فيه من الأفضل السماح لبعض الرسائل غير المرغوب فيها بالوصول إلى البريد الوارد بدلاً من إرسال رسالة إلكترونية مهمة للنشاط التجاري إلى مجلد الرسائل غير المرغوب فيها. لقد
دربت أحد أدوات تصنيف الرسائل غير المرغوب فيها لهذا الموقف حيث تكون الفئة الموجبة هي
الرسائل غير المرغوب فيها والفئة السالبة هي الرسائل غير غير المرغوب فيها.
أيّ من النقاط التالية
على منحنى ROC لفلترة البيانات هو الأفضل؟
النقطة "أ"
في حالة الاستخدام هذه، من الأفضل تقليل النتائج الموجبة الخاطئة،
حتى إذا انخفضت أيضًا النتائج الموجبة الصائبة.
النقطة ب
يوازن هذا الحدّ النتائج الموجبة الصائبة والخاطئة.
النقطة ج
ويؤدي هذا الحدّ إلى زيادة الإيجابيات الحقيقية إلى أقصى حدّ (الإبلاغ عن المزيد من الرسائل غير المرغوب فيها)
على حساب زيادة الإيجابيات الخاطئة (الإبلاغ عن المزيد من الرسائل الإلكترونية المشروعة على أنّها
غير مرغوب فيها).
تاريخ التعديل الأخير: 2025-05-23 (حسب التوقيت العالمي المتفَّق عليه)
[[["يسهُل فهم المحتوى.","easyToUnderstand","thumb-up"],["ساعَدني المحتوى في حلّ مشكلتي.","solvedMyProblem","thumb-up"],["غير ذلك","otherUp","thumb-up"]],[["لا يحتوي على المعلومات التي أحتاج إليها.","missingTheInformationINeed","thumb-down"],["الخطوات معقدة للغاية / كثيرة جدًا.","tooComplicatedTooManySteps","thumb-down"],["المحتوى قديم.","outOfDate","thumb-down"],["ثمة مشكلة في الترجمة.","translationIssue","thumb-down"],["مشكلة في العيّنات / التعليمات البرمجية","samplesCodeIssue","thumb-down"],["غير ذلك","otherDown","thumb-down"]],["تاريخ التعديل الأخير: 2025-05-23 (حسب التوقيت العالمي المتفَّق عليه)"],[],[],null,["# Classification: ROC and AUC\n\nThe previous section presented a set of model metrics, all calculated at a\nsingle classification threshold value. But if you want to evaluate a\nmodel's quality across all possible thresholds, you need different tools.\n\nReceiver-operating characteristic curve (ROC)\n---------------------------------------------\n\nThe [**ROC curve**](/machine-learning/glossary#roc-receiver-operating-characteristic-curve)\nis a visual representation of model performance across all thresholds.\nThe long version of the name, receiver operating characteristic, is a holdover\nfrom WWII radar detection.\n\nThe ROC curve is drawn by calculating the true positive rate (TPR)\nand false positive rate (FPR) at every possible threshold (in practice, at\nselected intervals), then graphing TPR over FPR. A perfect model,\nwhich at some threshold has a TPR of 1.0 and a FPR of 0.0, can\nbe represented by either a point at\n(0, 1) if all other thresholds are ignored, or by the following:\n**Figure 1.** ROC and AUC of a hypothetical perfect model.\n\nArea under the curve (AUC)\n--------------------------\n\nThe [**area under the ROC curve (AUC)**](/machine-learning/glossary#AUC)\nrepresents the probability that the model,\nif given a randomly chosen positive and negative example, will rank the\npositive higher than the negative.\n\nThe perfect model above, containing a square with sides of length 1, has an\narea under the curve (AUC) of 1.0. This means there is a 100% probability that\nthe model will correctly rank a randomly chosen positive example higher than a\nrandomly chosen negative example. In other words, looking at the spread of\ndata points below, AUC gives the probability that the model will place a\nrandomly chosen square to the right of a randomly chosen circle, independent of\nwhere the threshold is set.\n**Figure 2.** A spread of predictions for a binary classification model. AUC is the chance a randomly chosen square is positioned to the right of a randomly chosen circle.\n\nIn more concrete terms, a spam classifier with AUC\nof 1.0 always assigns a random spam email a higher probability of being\nspam than a random legitimate email. The actual classification of each\nemail depends on the threshold that you choose.\n\nFor a binary classifier, a model that does exactly as well as random guesses or\ncoin flips has a ROC that is a diagonal line from (0,0) to (1,1). The AUC is\n0.5, representing a 50% probability of correctly ranking a random positive and\nnegative example.\n\nIn the spam classifier example, a spam classifier with AUC of 0.5 assigns\na random spam email a higher probability of being spam than a random\nlegitimate email only half the time.\n**Figure 3.** ROC and AUC of completely random guesses. \n\n#### (Optional, advanced) Precision-recall curve\n\nAUC and ROC work well for comparing models when the dataset is roughly\nbalanced between classes. When the dataset is imbalanced, precision-recall\ncurves (PRCs) and the area under those curves may offer a better comparative\nvisualization of model performance. Precision-recall curves are created by\nplotting precision on the y-axis and recall on the x-axis across all\nthresholds.\n\nAUC and ROC for choosing model and threshold\n--------------------------------------------\n\nAUC is a useful measure for comparing the performance of two different models,\nas long as the dataset is roughly balanced. The model with greater area under\nthe curve is generally the better one.\n**Figure 4.** ROC and AUC of two hypothetical models. The curve on the right, with a greater AUC, represents the better of the two models.\n\nThe points on a ROC curve closest to (0,1) represent a range of the\nbest-performing thresholds for the given model. As discussed in the\n[Thresholds](/machine-learning/crash-course/classification/thresholding),\n[Confusion matrix](/machine-learning/crash-course/classification/thresholding#confusion_matrix)\nand\n[Choice of metric and tradeoffs](/machine-learning/crash-course/classification/accuracy-precision-recall#choice_of_metric_and_tradeoffs)\nsections, the threshold you choose depends on which metric is most important to\nthe specific use case. Consider the points A, B, and C in the following\ndiagram, each representing a threshold:\n**Figure 5.** Three labeled points representing thresholds.\n\nIf false positives (false alarms) are highly costly, it may make sense to\nchoose a threshold that gives a lower FPR, like the one at point A, even if TPR\nis reduced. Conversely, if false positives are cheap and false negatives\n(missed true positives) highly costly, the threshold for point C, which\nmaximizes TPR, may be preferable. If the costs are roughly equivalent, point B\nmay offer the best balance between TPR and FPR.\n\nHere is the ROC curve for the data we have seen before:\n\nExercise: Check your understanding\n----------------------------------\n\nIn practice, ROC curves are much less regular than the illustrations given above. Which of the following models, represented by their ROC curve and AUC, has the best performance? \nThis model has the highest AUC, which corresponds with the best performance. \nWhich of the following models performs worse than chance? \nThis model has an AUC lower than 0.5, which means it performs worse than chance. \nThis model performs slightly better than chance. \nThis model performs the same as chance. \nThis is a hypothetical perfect classifier. \n\n#### (Optional, advanced) Bonus question\n\nWhich of the following changes can be made to the worse-than-chance model in the previous question to cause it to perform better than chance? \nReverse the predictions, so predictions of **1** become **0** , and predictions of **0** become **1**. \nIf a binary classifier reliably puts examples in the wrong classes more often than chance, switching the class label immediately makes its predictions better than chance without having to retrain the model. \nHave it always predict the negative class. \nThis may or may not improve performance above chance. Also, as discussed in the [Accuracy](/machine-learning/crash-course/classification/accuracy-precision-recall#accuracy) section, this isn't a useful model. \nHave it always predict the positive class. \nThis may or may not improve performance above chance. Also, as discussed in the [Accuracy](/machine-learning/crash-course/classification/accuracy-precision-recall#accuracy) section, this isn't a useful model.\n\n\u003cbr /\u003e\n\nImagine a situation where it's better to allow some spam to reach the\ninbox than to send a business-critical email to the spam folder. You've\ntrained a spam classifier for this situation where the positive class is\nspam and the negative class is not-spam.\nWhich of the following points\non the ROC curve for your classifier is preferable? \nPoint A \nIn this use case, it's better to minimize false positives, even if true positives also decrease. \nPoint B \nThis threshold balances true and false positives. \nPoint C \nThis threshold maximizes true positives (flags more spam) at a cost of more false positives (more legitimate emails flagged as spam).\n| **Key terms:**\n|\n| - [Area under the ROC curve (AUC)](/machine-learning/glossary#AUC)\n- [ROC curve](/machine-learning/glossary#roc-receiver-operating-characteristic-curve) \n[Help Center](https://support.google.com/machinelearningeducation)"]]