Error in using tuneParams of MLR package

machine_learning
xgboost

#1

I just came across your This Machine Learning Project on Imbalanced Data Can Add Value to Your Resume article and i am tryng to run the same in my Rstudio. I got the below error while running the code in this line

xgb_tune <- tuneParams(learner = xgb_learner, task = train.task, resampling = set_cv,
measures = list(acc,tpr,tnr,fpr,fp,fn), par.set = xg_ps, control = rancontrol)

The dataset has both factor and numeric variables

#error
[Tune-x] 1: max_depth=5; lambda=0.146; eta=0.374; subsample=0.841; min_child_weight=8.23; colsample_bytree=0.587
Error in checkLearnerBeforeTrain(task, learner, weights) :
Task ‘d_train’ has factor inputs in ‘age, wage_per_hour, capital_gains, capital_loss…’, but learner ‘classif.xgboost’ does not support that!


#2

Previously, running xgboost with factors would convert all factors to their integer representation as an ordered factor. While other packages do this, mlr decided that would not be expected behavior.

Convert all of your factors to dummy variables with createDummyFeatures() then the code will run