python - 仅在 scikitplot 中的提升曲线和累积增益图表中绘制 1 类与基线的关系

标签 python scikit-learn scikit-plot

我正在研究广告事件的倾向建模问题。我的数据集由历史上点击过广告的用户和未点击过的用户组成。

为了衡量模型的性能,我使用 sklearn 绘制了累积增益和提升图。下面是相同的代码:

import matplotlib.pyplot as plt
import scikitplot as skplt

Y_test_pred_ = model.predict_proba(X_test_df)[:]

skplt.metrics.plot_cumulative_gain(Y_test, Y_test_pred_)
plt.show()

skplt.metrics.plot_lift_curve(Y_test, Y_test_pred_)
plt.show()

我得到的图显示了 0 类用户和 1 类用户的图表 sample cumulative gains curve sample lift chart

我只需要根据基线曲线绘制 1 类曲线。 有什么办法可以做到这一点吗?

最佳答案

您可以使用kds相同的包。

对于累积 yield 图:

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

对于提升图:

import kds
kds.metrics.plot_lift(y_test, y_prob)

示例

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

X, y = load_iris(return_X_y=True)
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])

# LIFT PLOT
kds.metrics.plot_lift(y_test, y_prob[:,1])

Cummulative Gains Plot Python Lift Plot Python

关于python - 仅在 scikitplot 中的提升曲线和累积增益图表中绘制 1 类与基线的关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58722650/

相关文章:

python - 使用 GridSearchCV 提前停止 - 使用保留的 CV 集进行验证

python - Sklearn K表示Clustering convergence

python - 如何在 Python 中将 2 条提升曲线的图合并为一个图

python - 使用带有 mysql 连接器 python 的上下文管理器

python - Pyplot/matplotlib 线图 - 相同颜色

python - 消息: unknown error: Chrome failed to start: exited abnormally on AWS Cloud9 with Linux 4. 9.85-38.58.amzn1.x86_64 x86_64

python - 当我运行 python 程序时,如何阻止命令提示符窗口打开?

python - 自定义 Transformer 单独工作,但将它们组合成一个 Pipeline 时会崩溃