0
我正在关注本教程链接https://www.tensorflow.org/tutorials/layers中的Tensorflow的“图层模块”。您可能能够帮助我如何获得预测结果及其各自的概率。 我需要查看它以进一步了解模型。如果有办法,我可以将结果 - 预测和概率保存到csv。Tensorflow:从“图层模块”提取预测
非常感谢你的时间。
我正在关注本教程链接https://www.tensorflow.org/tutorials/layers中的Tensorflow的“图层模块”。您可能能够帮助我如何获得预测结果及其各自的概率。 我需要查看它以进一步了解模型。如果有办法,我可以将结果 - 预测和概率保存到csv。Tensorflow:从“图层模块”提取预测
非常感谢你的时间。
我实际上已经找到了一个方法,这是非常简单的,因为我认为。我在想,有些人可能会有类似的问题,所以在这里。 Tensorflow是一种适用于机器学习模型的新框架,但我最终意识到这非常简单。
Tensorflow对你与TF创建的模型中,这* .predict(...)函数返回的预测变量定义你的模型包含“类”和“概率”
您的手机型号对于一个例子:
some_classifier = tf.estimator.Estimator(model_fn=model_fn,
model_dir=...)
您可以预测做到这一点(因为我们知道它)
prediction_input_fn = tf.estimator.inputs.numpy_input_fn(
x={"x": test_feats}, #given you have this variable containing the test data
y=test_labels, #and the equivalent label for the test data
num_epochs=1,
shuffle=False)
prediction_results = some_classifier.predict(input_fn=prediction_input_fn)
,然后变量prediction_r esults包含预测类和值的概率,然后可以保存(例如,使用熊猫)
save = panda.DataFrame(list(prediction_results))
save.to_csv("file.csv")
上面的代码剪断效果很好给你已经写了代码模型内的容器的预测,如下面:
predictions = {
"classes": tf.argmax(input=logits, axis=1),
"probabilities": tf.nn.softmax(logits, name="softmax_tensor")
}