如何从lm结果中获取RMSE? [英] How to obtain RMSE out of lm result?

查看:309
本文介绍了如何从lm结果中获取RMSE?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道$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.

备注

  • 给出两个向量xyc(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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆