我想编码一个采用输入功能并返回输出的神经网络。不过,我想通过比较输出与实际输出来检查NN的“正确性”。同时,我想让这个指标能够解释产出的不确定性。假设预测输出与实际输出相差1个单位以内,请将该预测输出计数为正确。tf.reduce_sum返回大于预期值
代码意图:检查| x-y |小于或等于1,如果这样的话所有发生的事情都是真的。基本上,我可以知道有多少案件是真的。
这里是下面的代码,
correct = tf.reduce_sum(tf.cast(tf.less_equal(tf.abs(x - y), 1), tf.int32))
correct.eval({x: predicted_output, y = real_output})
当我路过一个小名单的字典(下面的代码),我能回到正确的结果:
{x: [1,2,3,4,5], y: [1,2,3,1,1,]}
然而,当我通过预测产量和实际产量这是长度10 000,有时返回值是更多 10 000.
我正确地认为返回值必须小于10 000吗?如果是,那么我会犯什么错误,导致回报值超过10 000?
编辑以包括完整的上下的代码:
def neural_network_model(data):
hidden_1_layer = {"weights": tf.Variable(tf.random_normal([n_input, n_nodes_hl1])),
"biases": tf.Variable(tf.random_normal([n_nodes_hl1]))}
hidden_2_layer = {"weights": tf.Variable(tf.random_normal([n_nodes_hl1, n_nodes_hl2])),
"biases": tf.Variable(tf.random_normal([n_nodes_hl2]))}
hidden_3_layer = {"weights": tf.Variable(tf.random_normal([n_nodes_hl2, n_nodes_hl3])),
"biases": tf.Variable(tf.random_normal([n_nodes_hl3]))}
output_layer = {"weights": tf.Variable(tf.random_normal([n_nodes_hl3, n_output])),
"biases": tf.Variable(tf.random_normal([n_output]))}
l1 = tf.add(tf.matmul(data, hidden_1_layer["weights"]), hidden_1_layer["biases"])
l1 = tf.nn.relu(l1)
l2 = tf.add(tf.matmul(l1, hidden_2_layer["weights"]), hidden_2_layer["biases"])
l2 = tf.nn.relu(l2)
l3 = tf.add(tf.matmul(l2, hidden_3_layer["weights"]), hidden_3_layer["biases"])
l3 = tf.nn.relu(l3)
output = tf.matmul(l3, output_layer["weights"]) + output_layer["biases"]
return output
prediction = neural_network_model(x)
correct = tf.reduce_sum(tf.cast(tf.less_equal(tf.abs(prediction - y), 1), tf.int32))
correct.eval({x: val_features, y: val_label})
适用于我随机整数。你能告诉我你有多少班吗?是10000吗?你检查了x和y的最大值和最小值吗? – hars
@hars类的数量是一个。其单个连续输出NN。我编辑了这个问题以包含更多关于代码的信息。 未包含在编辑中,正在运行培训课程。在检查正确之前。 –
您是否检查过它的x,y和帽子值的大小? – hars