.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/snsx/plot_prplot_script.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_snsx_plot_prplot_script.py: plot_prplot_script with examples ========================================== An example showing the :py:func:`~scikitplot.snsx.prplot` function used by a scikit-learn regressor. .. GENERATED FROM PYTHON SOURCE LINES 8-12 .. code-block:: Python :lineno-start: 9 # Authors: The scikit-plots developers # SPDX-License-Identifier: BSD-3-Clause .. GENERATED FROM PYTHON SOURCE LINES 13-14 Import scikit-plot .. GENERATED FROM PYTHON SOURCE LINES 14-17 .. code-block:: Python :lineno-start: 14 import scikitplot.snsx as sp .. GENERATED FROM PYTHON SOURCE LINES 18-23 .. code-block:: Python :lineno-start: 18 ax = sp.prplot( x=[0, 1, 1, 0, 1, 0, 1, 1, 0, 1], y=[0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8 , 0.9, 1.0], ) .. image-sg:: /auto_examples/snsx/images/sphx_glr_plot_prplot_script_001.png :alt: PR (Precision-Recall) Curve :srcset: /auto_examples/snsx/images/sphx_glr_plot_prplot_script_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 24-33 .. code-block:: Python :lineno-start: 24 import numpy as np; np.random.seed(0) # reproducibility import pandas as pd df = pd.DataFrame({ "true": np.random.normal(0.5, 0.1, 100).round(), "prob": np.random.normal(0.5, 0.1, 100), "group": ["A", "A", "A", "A", "A", "B", "B", "B", "B", "B"]*10 }) .. GENERATED FROM PYTHON SOURCE LINES 34-35 PR Curve .. GENERATED FROM PYTHON SOURCE LINES 35-39 .. code-block:: Python :lineno-start: 35 ax = sp.prplot(x=df.true, y=df.prob, hue=df.group) # ax = sp.rocplot(df, x="true", y="prob", label=f"classA") .. image-sg:: /auto_examples/snsx/images/sphx_glr_plot_prplot_script_002.png :alt: PR (Precision-Recall) Curve :srcset: /auto_examples/snsx/images/sphx_glr_plot_prplot_script_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 40-61 .. code-block:: Python :lineno-start: 40 for i in range(10): np.random.seed(i) # reproducibility df = pd.DataFrame({ "true": np.random.normal(0.5, 0.1, 100).round(), "prob": np.random.normal(0.5, 0.1, 100), "group": ["A", "A", "A", "A", "A", "B", "B", "B", "B", "B"]*10 }) ax = sp.prplot(df, x="true", y="prob", label=f"{i}") # ax = sp.rocplot( # x=np.random.normal(0.5, 0.1, 100).round(), # y=np.random.normal(0.5, 0.1, 100), # label=f"{i}", # ) # --- Collect unique handles and labels --- handles, labels = ax.get_legend_handles_labels() by_label = dict(zip(labels, handles)) # deduplicate # Override legend ax.legend(by_label.values(), by_label.keys(), title="Legend") .. image-sg:: /auto_examples/snsx/images/sphx_glr_plot_prplot_script_003.png :alt: PR (Precision-Recall) Curve :srcset: /auto_examples/snsx/images/sphx_glr_plot_prplot_script_003.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.455 seconds) .. _sphx_glr_download_auto_examples_snsx_plot_prplot_script.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-plots/scikit-plots/main?urlpath=lab/tree/notebooks/auto_examples/snsx/plot_prplot_script.ipynb :alt: Launch binder :width: 150 px .. container:: lite-badge .. image:: images/jupyterlite_badge_logo.svg :target: ../../lite/lab/index.html?path=auto_examples/snsx/plot_prplot_script.ipynb :alt: Launch JupyterLite :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_prplot_script.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_prplot_script.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_prplot_script.zip ` .. include:: plot_prplot_script.recommendations .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_