TensorFlow - 无法获得预测

时间:2016-12-06 19:11:57

标签: python tensorflow neural-network kaggle

我正在尝试解决Titanic Problem on Kaggle,我不确定如何获取给定测试数据的输出。

我成功训练网络并调用方法make_prediction(x, test_x)

x = tf.placeholder('float', [None, ip_features])
...
def make_prediction(x, test_data):
  with tf.Session() as sess :
    sess.run(tf.global_variables_initializer())
    prediction = sess.run(y, feed_dict={x: test_data})
    return prediction


我不确定如何在这种情况下np.array传递test_data以获取包含预测np.array

0/1

Link to Full Code

1 个答案:

答案 0 :(得分:1)

我将您的train_neural_networkmake_prediction功能合并为一个功能。将tf.nn.softmax应用于模型函数会使值范围从0到1(解释为概率),然后tf.argmax以更高的概率提取列号。请注意,在这种情况下,placeholder的{​​{1}}需要进行一次热编码。 (如果你不是这里的热门编码,那么y会将pred_y=tf.round(tf.nn.softmax(model))的输出转换为0或1)

softmax