【问题标题】:R squared of predicted values预测值的 R 平方
【发布时间】:2015-12-04 12:34:56
【问题描述】:

考虑到预测函数及其 R 平方值,我有一个基本问题。

data<- datasets::faithful
# Linear model
model<- lm (eruptions~., data=data)
summary (model)[[9]] # R squared ajusted

# Creating test data to predict eruption values using the previous model
test.data<- data.frame(waiting= rnorm (80, mean = 70, sd = 14 ))
pred<- predict (model, test.data) # Predict eruptions based and the previou model

# New dataset with predicted values
newdata<- data.frame (eruptions = model.pred, waiting = test.data)

# Linear model to predicted values
new.model<- lm (eruptions~., data = newdata)
summary (new.model)[[9]] ## R-squared from predicted values

具有预测值的数据集的 R-squared 为 1。很明显,如果预测值基于 predict 函数中使用的相同变量,则 R-squared 测量的拟合是完美的 (=1)。但是,我的兴趣是衡量我的模型在 测试其他数据集方面的性能有多好,例如代码中的 test.data。我是否正确使用了预测功能?

提前致谢

【问题讨论】:

    标签: r predict


    【解决方案1】:

    将新变量作为 predict() 函数的“newdata”参数传递。

    在 R 控制台中输入 ?predict 以获取其 R 文档:

    新数据

    用于查找变量的可选数据框 预测。如果省略,则使用拟合值。

    【讨论】:

      猜你喜欢
      • 2016-08-28
      • 1970-01-01
      • 2018-07-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-06
      • 2016-10-15
      相关资源
      最近更新 更多