In the R language, often you have to convert variables to “factor” or “categorical”. There is a known issue in the ‘caret’ library that may cause errors when you do that in a certain way.

The **correct way** to convert variables to ‘factor’ is:

trainset$Churn = **as.factor**(trainset$Churn)

In particular, “the train() function in caret does not handle factor variables well” when you convert to factors using other methods.

(See https://rpubs.com/SulmanKhan/444033)

Basically, if you use other ways to convert to ‘factor’, the code may still run, but there may be some ‘weird’ issues that leads to inaccurate predictions (for instance if you are doing logistic regression, decision trees, etc.)

### Like this:

Like Loading...

*Related*