plot_classifier_eval with examples#

An example showing the plot_classifier_eval function used by a scikit-learn classifier.

 9 # Authors: The scikit-plots developers
10 # SPDX-License-Identifier: BSD-3-Clause

Import scikit-plots#

16 from sklearn.datasets import (
17     load_iris as data_3_classes,
18 )
19 from sklearn.linear_model import LogisticRegression
20 from sklearn.model_selection import train_test_split
21
22 import numpy as np
23
24 np.random.seed(0)  # reproducibility
25 # importing pylab or pyplot
26 # import matplotlib as mpl
27 import matplotlib.pyplot as plt
28
29 # Import scikit-plot
30 import scikitplot as sp

Loading the dataset#

36 # Load the data
37 X, y = data_3_classes(return_X_y=True, as_frame=True)
38 X_train, X_val, y_train, y_val = train_test_split(X, y, test_size=0.5, random_state=0)

Model Training#

44 # Create an instance of the LogisticRegression
45 model = LogisticRegression(max_iter=int(1e5), random_state=0).fit(X_train, y_train)
46
47 # Perform predictions
48 y_val_pred = model.predict(X_val)
49 y_train_pred = model.predict(X_train)

Plot!#

55 fig1 = sp.metrics.plot_classifier_eval(
56     y_val,
57     y_val_pred,
58     labels=np.unique(y_train),
59     figsize=(8, 2),
60     title="Val",
61     save_fig=True,
62     save_fig_filename="",
63     # overwrite=True,
64     add_timestamp=True,
65     # verbose=True,
66 )
67 # plt.show(block=True)
68 fig2 = sp.metrics.plot_classifier_eval(
69     y_train,
70     y_train_pred,
71     labels=np.unique(y_train),
72     figsize=(8, 2),
73     title="Train",
74     save_fig=True,
75     save_fig_filename="",
76     # overwrite=True,
77     add_timestamp=True,
78     # verbose=True,
79 )
  • Val Classification Report , Val Confusion Matrix
  • Train Classification Report , Train Confusion Matrix

Tags: model-type: classification model-workflow: model evaluation plot-type: matrix plot-type: specialty level: beginner purpose: showcase

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

Related examples

plot_silhouette with examples

plot_silhouette with examples

plot_confusion_matrix with examples

plot_confusion_matrix with examples

plot_precision_recall with examples

plot_precision_recall with examples

plot_roc_curve with examples

plot_roc_curve with examples

Gallery generated by Sphinx-Gallery