
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "auto_examples/evaluation/plot_classification_report.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. note::
        :class: sphx-glr-download-link-note

        :ref:`Go to the end <sphx_glr_download_auto_examples_evaluation_plot_classification_report.py>`
        to download the full example code.

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_auto_examples_evaluation_plot_classification_report.py:


=============================================
Evaluate classification by compiling a report
=============================================

Specific metrics have been developed to evaluate classifier which has been
trained using imbalanced data. We use `skore.evaluate` to get a structured
report of the classifier performance.

.. GENERATED FROM PYTHON SOURCE LINES 10-57





.. raw:: html

    <div class="output_subarea output_html rendered_html output_result">
    <div>
    <style scoped>
        .dataframe tbody tr th:only-of-type {
            vertical-align: middle;
        }

        .dataframe tbody tr th {
            vertical-align: top;
        }

        .dataframe thead th {
            text-align: right;
        }
    </style>
    <table border="1" class="dataframe">
      <thead>
        <tr style="text-align: right;">
          <th></th>
          <th></th>
          <th>LogisticRegression</th>
        </tr>
        <tr>
          <th>Metric</th>
          <th>Label / Average</th>
          <th></th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <th>Accuracy</th>
          <th></th>
          <td>0.872000</td>
        </tr>
        <tr>
          <th rowspan="2" valign="top">Precision</th>
          <th>0</th>
          <td>0.423868</td>
        </tr>
        <tr>
          <th>1</th>
          <td>0.980139</td>
        </tr>
        <tr>
          <th rowspan="2" valign="top">Recall</th>
          <th>0</th>
          <td>0.837398</td>
        </tr>
        <tr>
          <th>1</th>
          <td>0.875776</td>
        </tr>
        <tr>
          <th>ROC AUC</th>
          <th></th>
          <td>0.950029</td>
        </tr>
        <tr>
          <th>Log loss</th>
          <th></th>
          <td>0.278240</td>
        </tr>
        <tr>
          <th>Brier score</th>
          <th></th>
          <td>0.087971</td>
        </tr>
        <tr>
          <th>Fit time (s)</th>
          <th></th>
          <td>NaN</td>
        </tr>
        <tr>
          <th>Predict time (s)</th>
          <th></th>
          <td>0.000682</td>
        </tr>
      </tbody>
    </table>
    </div>
    </div>
    <br />
    <br />

.. code-block:: Python


    # Authors: Guillaume Lemaitre <g.lemaitre58@gmail.com>
    # License: MIT


    import skore
    from sklearn import datasets
    from sklearn.linear_model import LogisticRegression
    from sklearn.model_selection import train_test_split
    from sklearn.preprocessing import StandardScaler

    from imblearn import over_sampling as os
    from imblearn import pipeline as pl

    print(__doc__)

    RANDOM_STATE = 42

    # Generate a dataset
    X, y = datasets.make_classification(
        n_classes=2,
        class_sep=2,
        weights=[0.1, 0.9],
        n_informative=10,
        n_redundant=1,
        flip_y=0,
        n_features=20,
        n_clusters_per_class=4,
        n_samples=5000,
        random_state=RANDOM_STATE,
    )

    pipeline = pl.make_pipeline(
        StandardScaler(),
        os.SMOTE(random_state=RANDOM_STATE),
        LogisticRegression(max_iter=10_000),
    )

    # Split the data
    X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=RANDOM_STATE)

    # Train the classifier with balancing
    pipeline.fit(X_train, y_train)

    # Evaluate the classifier using skore
    report = skore.evaluate(pipeline, X_test, y_test, splitter="prefit")
    report.metrics.summarize().frame()


.. rst-class:: sphx-glr-timing

   **Total running time of the script:** (0 minutes 4.247 seconds)

**Estimated memory usage:**  300 MB


.. _sphx_glr_download_auto_examples_evaluation_plot_classification_report.py:

.. only:: html

  .. container:: sphx-glr-footer sphx-glr-footer-example

    .. container:: sphx-glr-download sphx-glr-download-jupyter

      :download:`Download Jupyter notebook: plot_classification_report.ipynb <plot_classification_report.ipynb>`

    .. container:: sphx-glr-download sphx-glr-download-python

      :download:`Download Python source code: plot_classification_report.py <plot_classification_report.py>`

    .. container:: sphx-glr-download sphx-glr-download-zip

      :download:`Download zipped: plot_classification_report.zip <plot_classification_report.zip>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
