【问题标题】:Tensorflow Regression is predicting insanely wrong valuesTensorflow Regression 正在预测非常错误的值
【发布时间】:2017-11-15 23:15:52
【问题描述】:

我目前正在为大学做练习。 任务是将给定的分类更改为回归。 我对数据的预处理和网络进行了所有更改,因此执行了回归。

但是当我尝试测试网络的预测时,预测的值非常错误。

数据是一个像素矩阵和一个0°到90°之间的对应角度。 我已将数据拆分为训练集和测试集,并检查了两组中的所有值都在 0° 到 90° 的范围内。

为了测试回归的准确性,我运行以下代码:

def reg_perceptron(t, weights, biases):
    t = tf.nn.relu(tf.add(tf.matmul(t, weights['h1']), biases['b1']), name = "layer_1")
    t = tf.add(tf.matmul(t, weights['hOut'], name="LOut_MatMul"), biases['bOut'], name = output_tensor)
    return t

pred = reg_perceptron(_x, rg_weights, rg_biases)


pred_y = np.array([])
total_batch_test = int(len(test_x)/batch_size)
for i in range(total_batch_test):
    lower_bound = i * batch_size
    upper_bound = i * batch_size + batch_size
    batch_test_x = test_x[lower_bound : upper_bound]#test_x are the pixel matrices of the test dataset
    feed_dict = {_x: batch_test_x}
    batch_test_y_predict = sess.run(pred, feed_dict = feed_dict)
    print ("min: %.2f max: %.2f" % (batch_test_y_predict.min(), batch_test_y_predict.max()))
    #WHY ARE THERE VALUES LIKE min: -13563819760524520849408.00 max: 1280719166070321053696.00 PREDICTED?

    if len(pred_y) == 0:
        pred_y = batch_test_y_predict
    else:
        pred_y = np.concatenate((pred_y, batch_test_y_predict), axis=0)

# Print test results.
pred_y = pd.Series(pred_y.reshape(-1).tolist())
#cut of the last elements if division by batch_size has rest
true_y = test_y[:pred_y.size]

RMSE = np.sqrt(np.mean(np.square(np.subtract(pred_y, true_y))))
print ("Epoch: %3.i - RMSE: %.2f" % (epoch, RMSE))

如果训练数据仅在 0° 到 90° 范围内,为什么预测值在 min: -13563819760524520849408.00 max: 1280719166070321053696.00 范围内?

因此我得到结果:Epoch: 0 - RMSE: 23738450191911909064704.00,显然应该在 90° 以下。

【问题讨论】:

  • pred 张量是如何定义的?
  • 还请记住,在此空间中时:90° = -270° = 450° = N * 90° 其中 N 是整数。
  • 我添加了pred的定义见编辑

标签: python tensorflow regression linear-regression


【解决方案1】:

我可以通过规范化给定数据来解决问题。

【讨论】:

    猜你喜欢
    • 2019-04-17
    • 2019-08-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-12
    • 1970-01-01
    • 2021-12-28
    • 1970-01-01
    相关资源
    最近更新 更多