python - Wide_deep分类器模型,需要预测概率值,不仅是 "best guess"

标签 python tensorflow ubuntu-16.04 python-3.5

我确实构建了一个基于宽而深的 Tensorflow 教程 ( here is its "Main" file this question is referring to ) 的二元分类器,这在很大程度上要归功于我在 SO 上获得的帮助,仅在“宽”模式下使用。

我用来提取分类猜测的函数是:

  pred_iter = model.predict(input_fn=lambda: input_fn(FLAGS.test_data, 1, False, 1))   for pred in pred_iter:
    print(pred['classes'])

它在分类方面效果很好,但分类返回的只是 01,因此缺乏概率方面。

我想要将分类表示为 0 到 1 之间的数字,以便了解网络对其猜测的“确定性”。

introduction itself说的是

We will train a logistic regression model, and given an individual's information our model will output a number between 0 and 1, which can be interpreted as the probability [...]

但我无法获得预测的这种概率方面。

我尝试使用许多答案中列出的 prob_a 函数,但它可能指的是旧版本的 TF,所以没有运气。

如何有效地将分类作为概率而不是“一次性”进行?

感谢任何帮助。

我在 Python 3.5、操作系统 Ubuntu 16.04 LTS 上使用 TF 1.8。

最佳答案

tf.estimator.LinearClassifier实例返回您可以使用的值的字典。您仅在代码中使用 pred[ 'classes' ],但概率值也位于 pred[ 'probabilities' ] 中。您也可以直接

print( pred )

它将输出与此类似的内容(带有虚拟数据):

{'logits': array([1.4264423], dtype=float32),
'logistic': array([0.80634636], dtype=float32),
'probabilities': array([0.19365363, 0.80634636], dtype=float32),
'class_ids': array(1),
'classes': array([b'1'], dtype=object) }

这样您就可以看到您还可以访问logitsclass_ids

第 1 类的概率是 pred[ 'probabilities' ] 中的第二个值,据我所知,这就是您想要使用的值。

关于python - Wide_deep分类器模型,需要预测概率值,不仅是 "best guess",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50316789/

相关文章:

Python:非常大的稀疏矩阵中的 lil_matrix 与 csr_matrix

Python 从另一个字典列表更新一个字典列表中的值

python - flask-login 中不存在 next_is_valid()?

python - 如何将坐标从列表同时传递到多个步进电机,而不是按顺序?

tensorflow - 如何在张量板中显示我的所有图像?

docker - 在docker上服务的TensorFlow对cuInit的调用失败:CUresult(-1)

arrays - tensorflow : Get indices of array rows which are zero

Gitlab无法在服务器上克隆,但可以在客户端克隆

r - Shiny 服务器: Generating downloadable PDF fails during compilation (code operational locally)

python-2.7 - 操作系统错误 : [Errno 40] Too many levels of symbolic links: '/home/ahmed/.virtualenvs/cv/bin/python'