使用预测语句时出错

时间:2015-09-14 07:33:11

标签: r prediction

当我运行R代码时,我收到以下错误:

 Error in as.data.frame.default(data) : 
 cannot coerce class ""lm"" to a data.frame
 Calls: predict ... model.frame.default -> as.data.frame ->   as.data.frame.default
 Execution halted  -> eval
 Execution halted

我的R代码:

delhi <- read.delim("delhi.tsv", na.strings = "")
delhi$lnprice <- log(delhi$price)
delhi$furn.f = factor(delhi$furnished)
delhi <- delhi [(delhi$facing %in% c ("East", "West", "North", "South", "South - East",  "South -West", "North - East", "North - West", NA)),]
delhi$fac.f = factor(delhi$facing)
delhi$age.f = factor(delhi$age)
delhi$own.f = factor (delhi$ownership)
delhi <- delhi[!table(delhi$locality)[delhi$locality]<20,]
delhi$loc.f = factor(delhi$locality)
delhi <- delhi [!(delhi$locality %in% c ("Sector-1")),]
heddel <- lm(lnprice ~ bedrooms+ area+ bathrooms+ balconies+ total_floors+ air_conditioned+ piped_gas+ power_back_up + security+ lift+ fac.f+age.f+own.f+loc.f, data = delhi)
deltest <- read.delim("UItest.txt", na.strings = "")
model2 <- lm(bedrooms ~bathrooms+area,data=deltest)
predict (heddel, model2)

任何帮助将不胜感激。

0 个答案:

没有答案