A similar question was asked however the link in the answer points to random forest example, it doesn\'t seem to work in my case.
Here is an example what I\'m trying
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.
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."