How to build a lift chart (a.k.a gains chart) in Python?

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about How to build a lift chart (a.k.a gains chart) in Python in Python. So Here I am Explain to you all the possible Methods here.

How to build a lift chart (a.k.a gains chart) in Python?

1. How to build a lift chart (a.k.a gains chart) in Python?

You can use the scikit-plot package to do the heavy lifting.
skplt.metrics.plot_cumulative_gain(y_test, predicted_probas)

2. build a lift chart (a.k.a gains chart) in Python

You can use the scikit-plot package to do the heavy lifting.
skplt.metrics.plot_cumulative_gain(y_test, predicted_probas)

Method 1

You can use the kds package for the same.

For Cummulative Gains Plot:

# pip install kds
import kds
kds.metrics.plot_cumulative_gain(y_test, y_prob)

Example

# REPRODUCABLE EXAMPLE
# Load Dataset and train-test split
from sklearn.model_selection import train_test_split
from sklearn import tree

X_train, X_test, y_train, y_test = train_test_split(X, y,
test_size=0.33,random_state=3)
clf = tree.DecisionTreeClassifier(max_depth=1,random_state=3)
clf = clf.fit(X_train, y_train)
y_prob = clf.predict_proba(X_test)

# CUMMULATIVE GAIN PLOT
import kds
kds.metrics.plot_cumulative_gain(y_test, y_prob[:,1])

Method 2

You can use the scikit-plot package to do the heavy lifting.

skplt.metrics.plot_cumulative_gain(y_test, predicted_probas)

Example

# The usual train-test split mumbo-jumbo
from sklearn.model_selection import train_test_split
from sklearn.naive_bayes import GaussianNB

X_train, X_test, y_train, y_test = train_test_split(X, y,
test_size=0.33)
nb = GaussianNB()
nb.fit(X_train, y_train)
predicted_probas = nb.predict_proba(X_test)

# The magic happens here
import matplotlib.pyplot as plt
import scikitplot as skplt
skplt.metrics.plot_cumulative_gain(y_test, predicted_probas)
plt.show()

This should result in a plot like this:

Summery

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.