Reputation: 133
I am new to parameter tuning with mlr package. I recently tried it with xgboost algorithm on a binary classification problem. I couldn’t get the trained accuracy, only NA. After google round, I was not able to debug my code. Could you give me some advice please?
Here is a reproducible example using mtcars data in R base:
library(mlr)
library(parallelMap)
mtcars
set.seed(1)
train.index=sample(nrow(mtcars),nrow(mtcars)*0.7)
train=mtcars[train.index,]
test=mtcars[-train.index,]
list(dim(train),dim(test))
# set the tuning
tune.dat=train[,c('mpg','cyl','disp','wt','vs','am')]
traintask=makeClassifTask(data=tune.dat,target='am')
learner=makeLearner('classif.xgboost',predict.type='response',nrounds=300,nthread=2)
prange=makeParamSet(
makeNumericParam('eta',lower=0.01,upper=0.3),
makeNumericParam('max_depth',lower=2,upper=10),
makeNumericParam('subsample',lower=0.4,upper=0.8),
makeNumericParam('colsample_bytree',lower=0.4,upper=0.8)
)
ctrl=makeTuneControlRandom(maxit=50)
rdesc=makeResampleDesc('CV',iters=4)
parallelStartMulticore(2)
# tune
mytune=tuneParams(learner=learner,task=traintask,par.set=prange,control=ctrl,resampling=rdesc)
mytune$y
the result should be a number rather than NA
Upvotes: 1
Views: 107
Reputation: 308
I found 2 issues with your code:
1)The 'am' field wants to be a factor
tune.dat[, 'am'] <- as.factor(tune.dat[, 'am'])
2)The max_depth parameter wants to be an integer
makeIntegerParam('max_depth', lower = 2, upper = 10),
With these substitutions the output is
mmce.test.mean
0.225
Upvotes: 2