我试图做一个简单的预测,使用线性回归,我有一个data.frame,其中一些项目是缺失的价格(因此注意到NA)。这一点完全行不通:
#Simple LR
fit <- lm(Price ~ Par1 + Par2 + Par3, data=combi[!is.na(combi$Price),])
Prediction <- predict(fit, data=combi[is.na(combi$Price),]), OOB=TRUE, type = "response")
我应该用什么代替data=combi[is.na(combi$Price),])
呢?
发布于 2014-03-16 12:37:40
将data
更改为newdata
。看看?predict.lm
,看看predict
可以采用什么参数。其他参数将被忽略。因此,在您的示例中,data
(和OOB
)被忽略,默认情况是返回对培训数据的预测。
Prediction <- predict(fit, newdata = combi[is.na(combi$Price),])
identical(predict(fit), predict(fit, data = combi[is.na(combi$Price),]))
## [1] TRUE
https://stackoverflow.com/questions/22442467
复制相似问题