且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在 Tensorflow 中计算 R^2

更新时间:2022-12-09 18:39:08

你在计算什么R^2"是

What you are computing the "R^2" is

与给定的表达式相比,您在错误的位置计算平均值.在进行除法之前,您应该在计算误差时取平均值.

compared to the given expression, you are computing the mean at the wrong place. You should take the mean when computing the errors, before doing the division.

unexplained_error = tf.reduce_sum(tf.square(tf.sub(y, prediction)))
total_error = tf.reduce_sum(tf.square(tf.sub(y, tf.reduce_mean(y))))
R_squared = tf.sub(1, tf.div(unexplained_error, total_error))