plot_lift with examples#

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

10 # Authors: The scikit-plots developers
11 # SPDX-License-Identifier: BSD-3-Clause
12
13 from sklearn.datasets import (
14     load_iris as data_3_classes,
15 )
16 from sklearn.linear_model import LogisticRegression
17 from sklearn.model_selection import train_test_split
18
19 import numpy as np
20
21 np.random.seed(0)  # reproducibility
22 # importing pylab or pyplot
23 import matplotlib.pyplot as plt
24
25 # Import scikit-plot
26 import scikitplot as sp
27
28 # Load the data
29 X, y = data_3_classes(return_X_y=True, as_frame=False)
30 X_train, X_val, y_train, y_val = train_test_split(X, y, test_size=0.5, random_state=0)
31
32 # Create an instance of the LogisticRegression
33 model = LogisticRegression(max_iter=int(1e5), random_state=0).fit(X_train, y_train)
34
35 # Perform predictions
36 y_val_prob = model.predict_proba(X_val)
37
38 # Plot!
39 ax = sp.kds.plot_lift(
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 )
Lift Curves

Tags: model-type: classification model-workflow: model evaluation plot-type: line plot-type: lift curve domain: statistics level: beginner purpose: showcase

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

Related examples

plot_cumulative_gain with examples

plot_cumulative_gain with examples

plot_ks_statistic with examples

plot_ks_statistic with examples

plot_feature_importances with examples

plot_feature_importances with examples

plot_silhouette with examples

plot_silhouette with examples

Gallery generated by Sphinx-Gallery