张量线性回归:获得调整后的R平方,系数,P值的值

问题描述 投票:4回答:3

与线性回归相关的关键参数很少,例如调整后的R平方,系数,P值,R平方,多R等。使用谷歌Tensorflow API实现线性回归时这些参数如何映射?有没有什么办法可以在模型执行之后/期间获得这些参数的值

tensorflow linear-regression p-value
3个回答
3
投票

根据我的经验,如果你想在模型运行时获得这些值,那么你必须使用tensorflow函数对它们进行手工编码。如果在模型运行后需要它们,可以使用scipy或其他实现。下面是一些如何编写R ^ 2,MAPE,RMSE的示例...

enter image description here

total_error = tf.reduce_sum(tf.square(tf.sub(y, tf.reduce_mean(y))))
unexplained_error = tf.reduce_sum(tf.square(tf.sub(y, prediction)))
R_squared = tf.sub(tf.div(total_error, unexplained_error),1.0)
R = tf.mul(tf.sign(R_squared),tf.sqrt(tf.abs(unexplained_error)))

MAPE = tf.reduce_mean(tf.abs(tf.div(tf.sub(y, prediction), y)))

RMSE = tf.sqrt(tf.reduce_mean(tf.square(tf.sub(y, prediction))))

0
投票

我相信R2的公式应该如下。请注意,当网络非常糟糕以至于它比仅仅作为预测器的平均值更糟糕时,它会变为负数:

total_error = tf.reduce_sum(tf.square(tf.subtract(y, tf.reduce_mean(y))))

unexplained_error = tf.reduce_sum(tf.square(tf.subtract(y, pred)))

R_squared = tf.subtract(1.0, tf.divide(unexplained_error, total_error)) 

0
投票

Adjusted_R_squared = 1 - [(1-R_squared)*(n-1)/(n-k-1)]

而n是观察数,k是特征数。

© www.soinside.com 2019 - 2024. All rights reserved.