Predicting Probabilities for GBM with caret library

淺唱寂寞╮ 提交于 2019-11-28 11:28:29

When class probabilities are requested, train puts them into a data frame with a column for each class. If the factor levels are not valid variable names, they are automatically changed (e.g. "0" becomes "X0"). train issues a warning in this case that goes something like "At least one of the class levels are not valid R variables names. This may cause errors if class probabilities are generated."

As topepo explained above, the function is getting confused by the variable names being generated.

If you run:

make.names(levels(traintestClass_subset))

and the result is different to how you have labelled the classes in your outcome variable than this issue will occur. Just make sure names generated by the piece of code above align with the class names you have provided to your factor and it should work.

It's the key:

I get a binary vector of predictions, which is good:

[1] 0 1 0 0 1 0 0 0 0 0 0 0 1 1 0 0 1 1 1 0 0 0 1 ...

Your factor labels could be interpret as numeric. I don't know why, but if you change 0 on 'a' and 1 on 'b' for instance, it will work without errors.

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