plot_ks_statistic with examples#

An example showing the plot_ks_statistic 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_breast_cancer as data_2_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_2_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_ks_statistic(
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 )
KS Statistic Plot

Tags: model-type: classification model-workflow: model evaluation plot-type: line plot-type: ks-statistic curve domain: statistics domain: KS (kolmogorov-smirnov) level: beginner purpose: showcase

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

Related examples

plot_lift with examples

plot_lift with examples

plot_cumulative_gain with examples

plot_cumulative_gain with examples

plot_learning_curve with examples

plot_learning_curve with examples

plot_precision_recall with examples

plot_precision_recall with examples

Gallery generated by Sphinx-Gallery