我正試圖在Tensorflow中進行迴歸。我不積極我正在計算R^2正確,因爲Tensorflow給了我一個比sklearn.metrics.r2_score
不同的答案有人可以看看我的下面的代碼,並讓我知道如果我正確實施了圖片方程。由於如何在Tensorflow中計算R^2
total_error = tf.square(tf.sub(y, tf.reduce_mean(y)))
unexplained_error = tf.square(tf.sub(y, prediction))
R_squared = tf.reduce_mean(tf.sub(tf.div(unexplained_error, total_error), 1.0))
R = tf.mul(tf.sign(R_squared),tf.sqrt(tf.abs(R_squared)))
在第三行tf.div,你有unexplained_error和total_error在錯誤的位置,他們需要進行切換。 –