python - 如何获得序列模型 Sklearn 的给定预测的概率
问题描述
我有一个顺序卷积神经网络模型,它正在 sklearns 手写数字数据集上进行训练,我现在正在评估模型并尝试从头开始创建 Roc 曲线,这需要我为我的测试数据获取 Tpr 和 Fpr,这样我就可以根据给定的阈值绘制它(据我了解)。我试图获得每个预测的预测概率,但我似乎无法弄清楚如何,我尝试过 predict_proba() 但我认为我的模型错误,有没有办法做到这一点,如果不是我可以如何进行绘图我的大鹏;我必须做一个conf吗?每个预测的矩阵,这似乎很啰嗦?
我在下面显示的另一篇文章中发现了一个 Roc 曲线函数,我试图获得“分数”
score = np.array([0.9, 0.8, 0.7, 0.6, 0.55, 0.54, 0.53, 0.52, 0.51, 0.505, 0.4, 0.39, 0.38, 0.37, 0.36, 0.35, 0.34, 0.33, 0.30, 0.1])
y = np.array([1,1,0, 1, 1, 1, 0, 0, 1, 0, 1,0, 1, 0, 0, 0, 1 , 0, 1, 0])
# false positive rate
fpr = []
# true positive rate
tpr = []
# Iterate thresholds from 0.0, 0.01, ... 1.0
thresholds = np.arange(0.0, 1.01, .01)
# get number of positive and negative examples in the dataset
P = sum(y)
N = len(y) - P
# iterate through all thresholds and determine fraction of true positives
# and false positives found at this threshold
for thresh in thresholds:
FP=0
TP=0
for i in range(len(score)):
if (score[i] > thresh):
if y[i] == 1:
TP = TP + 1
if y[i] == 0:
FP = FP + 1
fpr.append(FP/float(N))
tpr.append(TP/float(P))
plt.scatter(fpr, tpr)
plt.show()
解决方案
推荐阅读
- visual-studio-code - VS Code - HTML 标签包装问题
- angular - NgRx - 无限次触发减速器
- excel - 仅当相应行的数据包含文本“OPEN”时,我如何使用 SUMIF 计算列 M 中的总数?
- ansible - Ansible on a linux like OS 回答我需要回答的问题是
- c++ - cstdlib 无法使用 ::wcstombs 解决
- java - 在 Java 类中执行存储过程
- sql-server - 如何使用 azure devops 管道执行 sql 脚本
- bash - 带有 docker 命令的 Bash 脚本未通过 Crontab 运行
- c# - 自适应卡片 HTML 渲染未将复选框设置为选中
- ios - 创建自定义 SF 符号