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

Wide_deep classifier model, need to predict probability value, not only "best guess"

我确实构建了一个二元分类器,多亏了我在 SO 上获得的帮助,它基于广泛而深入的 Tensorflow 教程 (here is its "Main" file this question is referring to),仅在 "wide" 中使用模式。

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

  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 之间的数字的分类,以便知道 "how sure" 网络是它的猜测。

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 的旧版本,所以运气不好.

我怎样才能有效地将分类作为概率而不是 "one shot"?

感谢任何帮助。

我在 Python 3.5、OS Ubuntu 16.04 LTS 上使用 TF 1.8。

tf.estimator.LinearClassifier 实例 return 您可以使用的值字典。您仅在代码中使用 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

class1的概率是pred[ 'probabilities' ]中的第二个值,我理解的就是你要用的