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 )

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