plot_cumulative_gain with examples#
An example showing the plot_cumulative_gain
function used
by a scikit-learn classifier.
9 # Authors: The scikit-plots developers
10 # SPDX-License-Identifier: BSD-3-Clause
11
12 from sklearn.datasets import (
13 load_iris as data_3_classes,
14 )
15 from sklearn.linear_model import LogisticRegression
16 from sklearn.model_selection import train_test_split
17
18 import numpy as np
19
20 np.random.seed(0) # reproducibility
21 # importing pylab or pyplot
22 import matplotlib.pyplot as plt
23
24 # Import scikit-plot
25 import scikitplot as sp
26
27 # Load the data
28 X, y = data_3_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_cumulative_gain(
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.272 seconds)
Related examples