.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/classification/plot_classifier_eval_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_classification_plot_classifier_eval_script.py: plot_classifier_eval with examples ================================== An example showing the :py:func:`~scikitplot.api.metrics.plot_classifier_eval` function used by a scikit-learn classifier. .. GENERATED FROM PYTHON SOURCE LINES 8-12 .. code-block:: Python # Authors: The scikit-plots developers # SPDX-License-Identifier: BSD-3-Clause .. GENERATED FROM PYTHON SOURCE LINES 13-15 Import scikit-plots ------------------------ .. GENERATED FROM PYTHON SOURCE LINES 15-32 .. code-block:: Python from sklearn.datasets import ( load_iris as data_3_classes, ) from sklearn.linear_model import LogisticRegression from sklearn.model_selection import train_test_split import numpy as np np.random.seed(0) # reproducibility # importing pylab or pyplot # import matplotlib as mpl import matplotlib.pyplot as plt # Import scikit-plot import scikitplot as sp .. GENERATED FROM PYTHON SOURCE LINES 33-35 Loading the dataset ------------------------ .. GENERATED FROM PYTHON SOURCE LINES 35-40 .. code-block:: Python # Load the data X, y = data_3_classes(return_X_y=True, as_frame=True) X_train, X_val, y_train, y_val = train_test_split(X, y, test_size=0.5, random_state=0) .. GENERATED FROM PYTHON SOURCE LINES 41-43 Model Training -------------- .. GENERATED FROM PYTHON SOURCE LINES 43-51 .. code-block:: Python # Create an instance of the LogisticRegression model = LogisticRegression(max_iter=int(1e5), random_state=0).fit(X_train, y_train) # Perform predictions y_val_pred = model.predict(X_val) y_train_pred = model.predict(X_train) .. GENERATED FROM PYTHON SOURCE LINES 52-54 Plot! ------------------------ .. GENERATED FROM PYTHON SOURCE LINES 54-81 .. code-block:: Python fig1 = sp.metrics.plot_classifier_eval( y_val, y_val_pred, labels=np.unique(y_train), figsize=(8, 2), title="Val", save_fig=True, save_fig_filename="", # overwrite=True, add_timestamp=True, # verbose=True, ) # plt.show(block=True) fig2 = sp.metrics.plot_classifier_eval( y_train, y_train_pred, labels=np.unique(y_train), figsize=(8, 2), title="Train", save_fig=True, save_fig_filename="", # overwrite=True, add_timestamp=True, # verbose=True, ) .. rst-class:: sphx-glr-horizontal * .. image-sg:: /auto_examples/classification/images/sphx_glr_plot_classifier_eval_script_001.png :alt: Val Classification Report , Val Confusion Matrix :srcset: /auto_examples/classification/images/sphx_glr_plot_classifier_eval_script_001.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/classification/images/sphx_glr_plot_classifier_eval_script_002.png :alt: Train Classification Report , Train Confusion Matrix :srcset: /auto_examples/classification/images/sphx_glr_plot_classifier_eval_script_002.png :class: sphx-glr-multi-img .. GENERATED FROM PYTHON SOURCE LINES 82-90 .. tags:: model-type: classification model-workflow: model evaluation plot-type: heatmap plot-type: eval level: beginner purpose: showcase .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.722 seconds) .. _sphx_glr_download_auto_examples_classification_plot_classifier_eval_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/maintenance/0.4.X?urlpath=lab/tree/notebooks/auto_examples/classification/plot_classifier_eval_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/classification/plot_classifier_eval_script.ipynb :alt: Launch JupyterLite :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_classifier_eval_script.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_classifier_eval_script.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_classifier_eval_script.zip ` .. include:: plot_classifier_eval_script.recommendations .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_