plot_confusion_matrix with examples#
An example showing the plot_confusion_matrix
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_digits as data_10_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.pyplot as plt
27
28 # Import scikit-plot
29 import scikitplot as sp
Loading the dataset#
35 # Load the data
36 X, y = data_10_classes(return_X_y=True, as_frame=False)
37 X_train, X_val, y_train, y_val = train_test_split(X, y, test_size=0.5, random_state=0)
Model Training#
43 # Create an instance of the LogisticRegression
44 model = LogisticRegression(max_iter=int(1e5), random_state=0).fit(X_train, y_train)
45
46 # Perform predictions
47 y_val_pred = model.predict(X_val)
Plot!#
53 # Plot!
54 ax = sp.metrics.plot_confusion_matrix(
55 y_val,
56 y_val_pred,
57 normalize=False,
58 save_fig=True,
59 save_fig_filename="",
60 # overwrite=True,
61 add_timestamp=True,
62 # verbose=True,
63 )

Total running time of the script: (0 minutes 0.569 seconds)
Related examples