plot_report with examples#

An example showing the report function with a scikit-learn classifier (e.g., LogisticRegression) instance.

# Authors: The scikit-plots developers
# SPDX-License-Identifier: BSD-3-Clause
from sklearn.datasets import (
    load_breast_cancer as data_2_classes,
    # load_iris as data_3_classes,
)
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split

# importing pylab or pyplot
import matplotlib.pyplot as plt
import numpy as np; np.random.seed(0)  # reproducibility

# Import scikit-plot
import scikitplot as sp

# Load the data
X, y = data_2_classes(return_X_y=True, as_frame=False)
X_train, X_val, y_train, y_val = train_test_split(X, y, test_size=0.5, random_state=0)

# Create an instance of the LogisticRegression
model = LogisticRegression(max_iter=int(1e5), random_state=0).fit(X_train, y_train)

# Perform predictions
y_val_prob = model.predict_proba(X_val)
sp.kds.decile_table(
    y_val,
    y_val_prob,
    save_fig=True,
    save_fig_filename="",
    # overwrite=True,
    add_timestamp=True,
    # verbose=True,
    display_term_tables=True,
)
LABELS INFO:

 prob_min         : Minimum probability in a particular decile
 prob_max         : Minimum probability in a particular decile
 prob_avg         : Average probability in a particular decile
 cnt_events       : Count of events in a particular decile
 cnt_resp         : Count of responders in a particular decile
 cnt_non_resp     : Count of non-responders in a particular decile
 cnt_resp_rndm    : Count of responders if events assigned randomly in a particular decile
 cnt_resp_wiz     : Count of best possible responders in a particular decile
 resp_rate        : Response Rate in a particular decile [(cnt_resp/cnt_cust)*100]
 cum_events       : Cumulative sum of events decile-wise
 cum_resp         : Cumulative sum of responders decile-wise
 cum_resp_wiz     : Cumulative sum of best possible responders decile-wise
 cum_non_resp     : Cumulative sum of non-responders decile-wise
 cum_events_pct   : Cumulative sum of percentages of events decile-wise
 cum_resp_pct     : Cumulative sum of percentages of responders decile-wise
 cum_resp_pct_wiz : Cumulative sum of percentages of best possible responders decile-wise
 cum_non_resp_pct : Cumulative sum of percentages of non-responders decile-wise
 KS               : KS Statistic decile-wise
 lift             : Cumuative Lift Value decile-wise
decile prob_min prob_max prob_avg cnt_cust cnt_resp cnt_non_resp cnt_resp_rndm cnt_resp_wiz resp_rate cum_cust cum_resp cum_resp_wiz cum_non_resp cum_cust_pct cum_resp_pct cum_resp_pct_wiz cum_non_resp_pct KS lift
0 1 1.000 1.000 1.000 29.0 29.0 0.0 18.4 29 100.000 29.0 29.0 29 0.0 10.175 15.761 15.761 0.000 15.761 1.549
1 2 0.999 1.000 1.000 28.0 28.0 0.0 18.4 28 100.000 57.0 57.0 57 0.0 20.000 30.978 30.978 0.000 30.978 1.549
2 3 0.998 0.999 0.999 29.0 29.0 0.0 18.4 29 100.000 86.0 86.0 86 0.0 30.175 46.739 46.739 0.000 46.739 1.549
3 4 0.993 0.997 0.996 28.0 28.0 0.0 18.4 28 100.000 114.0 114.0 114 0.0 40.000 61.957 61.957 0.000 61.957 1.549
4 5 0.960 0.992 0.980 29.0 29.0 0.0 18.4 29 100.000 143.0 143.0 143 0.0 50.175 77.717 77.717 0.000 77.717 1.549
5 6 0.772 0.956 0.888 28.0 25.0 3.0 18.4 28 89.286 171.0 168.0 171 3.0 60.000 91.304 92.935 2.970 88.334 1.522
6 7 0.066 0.769 0.346 29.0 16.0 13.0 18.4 13 55.172 200.0 184.0 184 16.0 70.175 100.000 100.000 15.842 84.158 1.425
7 8 0.000 0.048 0.011 28.0 0.0 28.0 18.4 0 0.000 228.0 184.0 184 44.0 80.000 100.000 100.000 43.564 56.436 1.250
8 9 0.000 0.000 0.000 29.0 0.0 29.0 18.4 0 0.000 257.0 184.0 184 73.0 90.175 100.000 100.000 72.277 27.723 1.109
9 10 0.000 0.000 0.000 28.0 0.0 28.0 18.4 0 0.000 285.0 184.0 184 101.0 100.000 100.000 100.000 100.000 0.000 1.000


Plot!

ax = sp.kds.report(
    y_val,
    y_val_prob,
    save_fig=True,
    save_fig_filename="",
    # overwrite=True,
    add_timestamp=True,
    # verbose=True,
    display_term_tables=True,
)
KS Statistic Plot
LABELS INFO:

 prob_min         : Minimum probability in a particular decile
 prob_max         : Minimum probability in a particular decile
 prob_avg         : Average probability in a particular decile
 cnt_events       : Count of events in a particular decile
 cnt_resp         : Count of responders in a particular decile
 cnt_non_resp     : Count of non-responders in a particular decile
 cnt_resp_rndm    : Count of responders if events assigned randomly in a particular decile
 cnt_resp_wiz     : Count of best possible responders in a particular decile
 resp_rate        : Response Rate in a particular decile [(cnt_resp/cnt_cust)*100]
 cum_events       : Cumulative sum of events decile-wise
 cum_resp         : Cumulative sum of responders decile-wise
 cum_resp_wiz     : Cumulative sum of best possible responders decile-wise
 cum_non_resp     : Cumulative sum of non-responders decile-wise
 cum_events_pct   : Cumulative sum of percentages of events decile-wise
 cum_resp_pct     : Cumulative sum of percentages of responders decile-wise
 cum_resp_pct_wiz : Cumulative sum of percentages of best possible responders decile-wise
 cum_non_resp_pct : Cumulative sum of percentages of non-responders decile-wise
 KS               : KS Statistic decile-wise
 lift             : Cumuative Lift Value decile-wise

Tags: model-type: classification model-workflow: model evaluation plot-type: line plot-type: decile level: beginner purpose: showcase

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

Related examples

plot_cumulative_gain with examples

plot_cumulative_gain with examples

plot_ks_statistic with examples

plot_ks_statistic with examples

plot_lift with examples

plot_lift with examples

plot_precision_recall with examples

plot_precision_recall with examples

Gallery generated by Sphinx-Gallery