如何从lm结果中获取RMSE?

编程入门 行业动态 更新时间:2024-10-10 01:24:36
本文介绍了如何从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.

备注

  • 给出两个向量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?

本文发布于:2023-11-24 11:55:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1625103.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:lm   RMSE

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!