问题描述
我目前正在运行以下模型:
pv_model <- lm(SalePrice ~ MSSubClass + MSZoning + ...,data = House_Train)
summary(pv_model)
pv_predict <- predict(pv_model,newdata = House_Test,type = "response")
House_Train$PV <- pv_predict
我遇到了这个错误:
Error in model.frame.default(Terms,newdata,na.action = na.action,xlev = object$xlevels) :
factor Foundation has new levels Slab
我检查了我的 House_Train 和 House_Test 数据框,看看“Slab”是否是来自以下任一者的缺失因子水平:
House_Test %>%
filter(Foundation == "Slab")
House_Train %>%
filter(Foundation == "Slab")
我得到以下测试输出:
Id MSSubClass MSZoning LotFrontage LotArea Street Alley LotShape LandContour Utilities
<dbl> <dbl> <fct> <dbl> <dbl> <fct> <fct> <fct> <fct> <fct>
1 1594 90 RH 60 7200 Pave Pave Reg Lvl AllPub
2 1730 90 RL 75 8250 Pave None Reg Lvl AllPub
3 1779 20 RL 75 9533 Pave None Reg Lvl AllPub
4 1848 20 RL NA 9000 Pave None Reg Lvl AllPub
5 1858 90 RL 64 7018 Pave None Reg Lvl AllPub
对于火车:
Id MSSubClass MSZoning LotFrontage LotArea Street Alley LotShape LandContour Utilities
<dbl> <dbl> <fct> <dbl> <dbl> <fct> <fct> <fct> <fct> <fct>
1 18 90 RL 72 10791 Pave NA Reg Lvl AllPub
2 91 20 RL 60 7200 Pave NA Reg Lvl AllPub
3 103 90 RL 64 7018 Pave NA Reg Bnk AllPub
4 343 90 RL NA 8544 Pave NA Reg Lvl AllPub
5 363 85 RL 64 7301 Pave NA Reg Lvl AllPub
据我所知,两个数据框都包含 Foundation == "Slab" 的多个实例。但是,我似乎无法解决此错误。我觉得很奇怪,因为我只使用这两个数据框;我不明白哪里可能缺少因子水平。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)