我正在研究广告事件的倾向建模问题。我的数据集由历史上点击过广告的用户和未点击过的用户组成。
为了衡量模型的性能,我使用 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()
我只需要根据基线曲线绘制 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])
关于python - 仅在 scikitplot 中的提升曲线和累积增益图表中绘制 1 类与基线的关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58722650/