我正在尝试在 Tensorflow 中进行回归。我不确定我计算 R^2 是否正确,因为 Tensorflow 给出的答案与sklearn.metrics.r2_score
有人可以看看我下面的代码,让我知道我是否正确地实现了图中的方程。谢谢
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)))
您计算的“R^2”是
与给定的表达式相比,您在错误的位置计算平均值。在进行除法之前计算误差时应该取平均值。
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))
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)