Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何获得序列模型Sklearn给定预测的概率_Python_Numpy_Tensorflow_Scikit Learn - Fatal编程技术网

Python 如何获得序列模型Sklearn给定预测的概率

Python 如何获得序列模型Sklearn给定预测的概率,python,numpy,tensorflow,scikit-learn,Python,Numpy,Tensorflow,Scikit Learn,我有一个顺序卷积神经网络模型,它正在sklearns手写数字数据集上训练,我现在正在评估该模型,并试图从头开始创建Roc曲线,这需要我获得测试数据的Tpr和Fpr,以便我可以根据给定阈值(据我所知)绘制它。我试图得到每个预测的预测概率,但我似乎不知道如何,我尝试了预测概率()但我认为我的模型错了,有没有办法做到这一点,如果没有,我如何绘制我的Roc;我是否必须为每个预测做一个配置矩阵,这似乎很冗长 我在下面的另一个post-Ill显示屏上发现了一个Roc曲线函数,我正在尝试获取“分数” scor

我有一个顺序卷积神经网络模型,它正在sklearns手写数字数据集上训练,我现在正在评估该模型,并试图从头开始创建Roc曲线,这需要我获得测试数据的Tpr和Fpr,以便我可以根据给定阈值(据我所知)绘制它。我试图得到每个预测的预测概率,但我似乎不知道如何,我尝试了预测概率()但我认为我的模型错了,有没有办法做到这一点,如果没有,我如何绘制我的Roc;我是否必须为每个预测做一个配置矩阵,这似乎很冗长

我在下面的另一个post-Ill显示屏上发现了一个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()