plot_report with examples#

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

 9 # Authors: The scikit-plots developers
10 # SPDX-License-Identifier: BSD-3-Clause
13 from sklearn.datasets import (
14     load_breast_cancer as data_2_classes,
15     # load_iris as data_3_classes,
16 )
17 from sklearn.linear_model import LogisticRegression
18 from sklearn.model_selection import train_test_split
19
20 # importing pylab or pyplot
21 import matplotlib.pyplot as plt
22 import numpy as np; np.random.seed(0)  # reproducibility
23
24 # Import scikit-plot
25 import scikitplot as sp
26
27 # Load the data
28 X, y = data_2_classes(return_X_y=True, as_frame=False)
29 X_train, X_val, y_train, y_val = train_test_split(X, y, test_size=0.5, random_state=0)
30
31 # Create an instance of the LogisticRegression
32 model = LogisticRegression(max_iter=int(1e5), random_state=0).fit(X_train, y_train)
33
34 # Perform predictions
35 y_val_prob = model.predict_proba(X_val)
39 sp.kds.decile_table(
40     y_val,
41     y_val_prob,
42     save_fig=True,
43     save_fig_filename="",
44     # overwrite=True,
45     add_timestamp=True,
46     # verbose=True,
47     display_term_tables=True,
48 )
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!

53 ax = sp.kds.report(
54     y_val,
55     y_val_prob,
56     save_fig=True,
57     save_fig_filename="",
58     # overwrite=True,
59     add_timestamp=True,
60     # verbose=True,
61     display_term_tables=True,
62 )
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: cum-gain curve level: beginner purpose: showcase

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

Related examples

plot_cumulative_gain with examples

plot_cumulative_gain with examples

plot_lift with examples

plot_lift with examples

plot_ks_statistic with examples

plot_ks_statistic with examples

plot_precision_recall with examples

plot_precision_recall with examples

Gallery generated by Sphinx-Gallery