我怎样才能以下面的方式绘制我的班级的概率分布?

数据挖掘 分类 xgboost 可能性 matplotlib
2022-02-18 16:23:44

全部,

我想绘制以下内容:

在此处输入图像描述

我有一个二进制分类问题,我在下面使用 xgboost 作为我的“模型”:

y_pred = model.predict_proba(x_test)[:, 1]

probabilities = pd.DataFrame({
            'prediction': y_pred,
            'output': y_true
        })


        colors = ['g', 'r']
        for output in [0, 1]:
            probabilities[probabilities['output'] == output]['prediction'] \
                .plot(kind='kde', ax=ax2, legend=True, color=colors[output])
        ax2.set_xlim(prob_xlims)
        ax2.set_xlabel('Predicted probability')
        ax2.set_title('Predicted probabilities and true labels (color)')

        # Legend
        handles, labels = ax2.get_legend_handles_labels()
        ax2.legend(handles, ['Class 0', 'Class 1'])

使用上面我怎样才能得到一个类似于上面的情节?如果错了也请纠正我,但predict_proba会返回probability(class x | data sample)其中数据样本是单行数据..?

0个回答
没有发现任何回复~