Error in `contrasts' Error

爷,独闯天下 提交于 2019-12-01 21:18:01

I think you have to provide factor levels in the trainings data to the test set as well. Something like the following should work.

newDriveTime <- data.frame(driveTime =  8, 
                    Market.y = factor("Dallas", levels(finalSubset$Market.y)))

predict(bestMod_Rescaled, newDriveTime)

In R, factor are saved as integers with names / labels. If you have two factor vectors with different number of levels, just by looking at the labels, one can not be sure which labels are the corresponding levels in the two vectors.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!