plot_lift with examples#
An example showing the plot_lift
function
with a scikit-learn classifier (e.g., LogisticRegression
) instance.
10 # Authors: The scikit-plots developers
11 # SPDX-License-Identifier: BSD-3-Clause
12
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)
36
37 # Plot!
38 ax = sp.kds.plot_lift(
39 y_val,
40 y_val_prob,
41 save_fig=True,
42 save_fig_filename="",
43 # overwrite=True,
44 add_timestamp=True,
45 # verbose=True,
46 )

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