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