R's caret training errors when y is not a factor

狂风中的少年 提交于 2019-12-02 02:12:01

As the error message states, y must be a factor (here, y is the name of the second parameter to the function). In R, a factor variable is used to represent categorical data. You can turn y into a factor with factor(y) but it will just have the levels 1:7 for your data. If you want to give more meaningful values to your factor, try

train$Cover_Type <- factor(train$Cover_Type, levels=1:7, 
    labels=c("Spruce/Fir","Lodgepole Pine","Ponderosa Pine",
    "Cottonwood/Willow","Aspen",
    "Douglas-fir","Krummholz"))

That will make your function happier and give you more useful labels in the results

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