我知道$sigma与均方根误差的概念之间存在微小差异.因此,我想知道从 R 中的lm函数中获取RMSE的最简单方法是什么?
I know there is a small difference between $sigma and the concept of root mean squared error. So, i am wondering what is the easiest way to obtain RMSE out of lm function in R?
res<-lm(randomData$price ~randomData$carat+ randomData$cut+randomData$color+ randomData$clarity+randomData$depth+ randomData$table+randomData$x+ randomData$y+randomData$z) length(coefficients(res))包含24个系数,因此我无法再手动制作模型. 因此,如何根据从lm得出的系数来评估RMSE?
contains 24 coefficient, and I cannot make my model manually anymore. So, how can I evaluate the RMSE based on coefficients derived from lm?
推荐答案残差平方和:
RSS <- c(crossprod(res$residuals))均方误差:
MSE <- RSS / length(res$residuals)MSE根目录
RMSE <- sqrt(MSE)Pearson估计的剩余方差(由summary.lm返回):
Pearson estimated residual variance (as returned by summary.lm):
sig2 <- RSS / res$df.residual从统计上讲,MSE是残差方差的最大似然估计量,但有偏差(向下). Pearson 1是残差方差的受限最大似然估计,它是无偏的.
Statistically, MSE is the maximum likelihood estimator of residual variance, but is biased (downward). The Pearson one is the restricted maximum likelihood estimator of residual variance, which is unbiased.
备注
- 给出两个向量x和y,c(crossprod(x, y))等效于sum(x * y),但快得多 . c(crossprod(x))同样比sum(x ^ 2)快.
- sum(x) / length(x)比mean(x) 更快.
- Given two vectors x and y, c(crossprod(x, y)) is equivalent to sum(x * y) but much faster. c(crossprod(x)) is likewise faster than sum(x ^ 2).
- sum(x) / length(x) is also faster than mean(x).
更多推荐
如何从lm结果中获取RMSE?
发布评论