plot_cumulative_gain#
- scikitplot.kds.plot_cumulative_gain(y_true, y_probas, *, pos_label=None, class_index=1, title='Cumulative Gain Plot', ax=None, fig=None, figsize=None, title_fontsize='large', text_fontsize='medium', data=None, **kwargs)[source]#
Generates the Decile-wise Lift Plot from labels and probabilities
The lift curve is used to determine the effectiveness of a binary classifier. A detailed explanation can be found at http://www2.cs.uregina.ca/~dbd/cs831/notes/lift_chart/lift_chart.html The implementation here works only for binary classification.
- Parameters:
- y_truearray-like of shape (n_samples,)
Ground truth (correct) target values.
- y_probasarray-like of shape (n_samples,) or (n_samples, n_classes)
Predicted probabilities for each class or only target class probabilities. If 1D, it is treated as probabilities for the positive class in binary or multiclass classification with the
class_index
.- class_indexint, optional, default=1
Index of the class of interest for multi-class classification. Ignored for binary classification.
- titlestr, optional, default=’Cumulative Gain Curves’
Title of the generated plot.
- axlist of matplotlib.axes.Axes, optional, default=None
The axis to plot the figure on. If None is passed in the current axes will be used (or generated if required). Axes like
fig.add_subplot(1, 1, 1)
orplt.gca()
- figmatplotlib.pyplot.figure, optional, default: None
The figure to plot the Visualizer on. If None is passed in the current plot will be used (or generated if required).
Added in version 0.3.9.
- figsizetuple of int, optional, default=None
Size of the figure (width, height) in inches.
- title_fontsizestr or int, optional, default=’large’
Font size for the plot title.
- text_fontsizestr or int, optional, default=’medium’
Font size for the text in the plot.
- Returns:
- matplotlib.axes.Axes
The axes with the plotted cumulative gain curves.
Notes
The implementation is specific to binary classification.
References
[1] http://mlwiki.org/index.php/Cumulative_Gain_Chart
Examples
>>> from sklearn.datasets import load_iris as data_3_classes >>> from sklearn.model_selection import train_test_split >>> from sklearn.linear_model import LogisticRegression >>> import scikitplot as skplt >>> X, y = data_3_classes(return_X_y=True, as_frame=False) >>> X_train, X_val, y_train, y_val = train_test_split(X, y, test_size=0.5, random_state=0) >>> model = LogisticRegression(max_iter=int(1e5), random_state=0).fit(X_train, y_train) >>> y_probas = model.predict_proba(X_val) >>> skplt.kds.plot_cumulative_gain( >>> y_val, y_probas, class_index=1, >>> );
(
Source code
,png
)
Gallery examples#
plot_cumulative_gain with examples