plot_cumulative_gain with examples#
An example showing the plot_cumulative_gain
function
with a scikit-learn classifier (e.g., LogisticRegression
) instance.
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 import numpy as np
21
22 np.random.seed(0) # reproducibility
23 # importing pylab or pyplot
24 import matplotlib.pyplot as plt
25
26 # Import scikit-plot
27 import scikitplot as sp
28
29 # Load the data
30 X, y = data_2_classes(return_X_y=True, as_frame=False)
31 X_train, X_val, y_train, y_val = train_test_split(X, y, test_size=0.5, random_state=0)
32
33 # Create an instance of the LogisticRegression
34 model = LogisticRegression(max_iter=int(1e5), random_state=0).fit(X_train, y_train)
35
36 # Perform predictions
37 y_val_prob = model.predict_proba(X_val)
38
39 # Plot!
40 ax = sp.kds.plot_cumulative_gain(
41 y_val,
42 y_val_prob,
43 save_fig=True,
44 save_fig_filename="",
45 # overwrite=True,
46 add_timestamp=True,
47 # verbose=True,
48 )

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