.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/miscellaneous/plot_roc_curve_visualization_api.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. or to run this example in your browser via JupyterLite or Binder .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_miscellaneous_plot_roc_curve_visualization_api.py: ============================================= منحنى ROC مع واجهة برمجة التطبيقات للتصور ============================================= يعرّف Scikit-learn واجهة برمجة تطبيقات بسيطة لإنشاء تصورات للتعلم الآلي. الميزات الرئيسية لهذه الواجهة هي السماح بالرسم السريع والتعديلات المرئية دون إعادة الحساب. في هذا المثال، سوف نوضح كيفية استخدام واجهة برمجة التطبيقات للتصور من خلال مقارنة منحنيات ROC. .. GENERATED FROM PYTHON SOURCE LINES 8-12 .. code-block:: Python # المؤلفون: مطوري scikit-learn # معرف SPDX-License: BSD-3-Clause .. GENERATED FROM PYTHON SOURCE LINES 13-16 تحميل البيانات وتدريب SVC ------------------------- أولاً، نقوم بتحميل مجموعة بيانات النبيذ وتحويلها إلى مشكلة تصنيف ثنائي. ثم نقوم بتدريب مصنف ناقل الدعم على مجموعة بيانات التدريب. .. GENERATED FROM PYTHON SOURCE LINES 16-31 .. code-block:: Python import matplotlib.pyplot as plt from sklearn.datasets import load_wine from sklearn.ensemble import RandomForestClassifier from sklearn.metrics import RocCurveDisplay from sklearn.model_selection import train_test_split from sklearn.svm import SVC X, y = load_wine(return_X_y=True) y = y == 2 X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=42) svc = SVC(random_state=42) svc.fit(X_train, y_train) .. raw:: html
SVC(random_state=42)
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.


.. GENERATED FROM PYTHON SOURCE LINES 32-37 رسم منحنى ROC ---------------------- بعد ذلك، نرسم منحنى ROC باستخدام مكالمة واحدة لـ :func:`sklearn.metrics.RocCurveDisplay.from_estimator`. الكائن `svc_disp` الذي يتم إرجاعه يسمح لنا بالاستمرار في استخدام منحنى ROC المحسوب بالفعل لـ SVC في الرسوم البيانية المستقبلية. .. GENERATED FROM PYTHON SOURCE LINES 37-40 .. code-block:: Python svc_disp = RocCurveDisplay.from_estimator(svc, X_test, y_test) plt.show() .. image-sg:: /auto_examples/miscellaneous/images/sphx_glr_plot_roc_curve_visualization_api_001.png :alt: plot roc curve visualization api :srcset: /auto_examples/miscellaneous/images/sphx_glr_plot_roc_curve_visualization_api_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 41-47 تدريب غابة عشوائية ورسم منحنى ROC --------------------------------------------------- نقوم بتدريب مصنف الغابة العشوائية وإنشاء رسم بياني يقارنه بمنحنى ROC لـ SVC. لاحظ كيف أن `svc_disp` يستخدم :func:`~sklearn.metrics.RocCurveDisplay.plot` لرسم منحنى ROC لـ SVC دون إعادة حساب قيم منحنى ROC نفسه. علاوة على ذلك، نقوم بتمرير `alpha=0.8` إلى دالات الرسم لتعديل قيم ألفا للمنحنيات. .. GENERATED FROM PYTHON SOURCE LINES 47-52 .. code-block:: Python rfc = RandomForestClassifier(n_estimators=10, random_state=42) rfc.fit(X_train, y_train) ax = plt.gca() rfc_disp = RocCurveDisplay.from_estimator(rfc, X_test, y_test, ax=ax, alpha=0.8) svc_disp.plot(ax=ax, alpha=0.8) plt.show() .. image-sg:: /auto_examples/miscellaneous/images/sphx_glr_plot_roc_curve_visualization_api_002.png :alt: plot roc curve visualization api :srcset: /auto_examples/miscellaneous/images/sphx_glr_plot_roc_curve_visualization_api_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.168 seconds) .. _sphx_glr_download_auto_examples_miscellaneous_plot_roc_curve_visualization_api.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: binder-badge .. image:: images/binder_badge_logo.svg :target: https://mybinder.org/v2/gh/scikit-learn/scikit-learn/main?urlpath=lab/tree/notebooks/auto_examples/miscellaneous/plot_roc_curve_visualization_api.ipynb :alt: Launch binder :width: 150 px .. container:: lite-badge .. image:: images/jupyterlite_badge_logo.svg :target: ../../lite/lab/index.html?path=auto_examples/miscellaneous/plot_roc_curve_visualization_api.ipynb :alt: Launch JupyterLite :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_roc_curve_visualization_api.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_roc_curve_visualization_api.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_roc_curve_visualization_api.zip ` .. include:: plot_roc_curve_visualization_api.recommendations .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_