library(mlr3) # load the mlr3 package
library(mlr3learners) # load the mlr3learners package
task <- tsk('iris') # define task
wrapper <- lrn('classif.rpart') # define wrapper
measure <- msr('classif.acc')
# run spsa
spsaMod <- spFeatureSelection( task = task,
wrapper = wrapper,
scoring = measure,
num.features.selected = 3,
n.jobs = 1,
iters.max = 2,
num.grad.avg = 1)
# obtain summary
summary(spsaMod)
# plot spsaMod
plot(spsaMod) # simplest plot
plot(spsaMod, errorBar = TRUE) # plot with error bars
plot(spsaMod, errorBar = TRUE, se = TRUE) # plot with error bars based on se
plot(spsaMod, errorBar = TRUE, annotateBest = TRUE) # annotate best value
plot(spsaMod, errorBar = TRUE, ylab = 'Acc measure', type = 'o')
# obtain the wrapped model with the best performing features
bestMod <- getBestModel(spsaMod)
# predict using the best mod
pred <- bestMod$predict( task = spsaMod$task.spfs )
# Obtain confusion matrix
pred$confusion
# Get the importance ranks of best performing features
getImportance(spsaMod)
plotImportance(spsaMod)
Run the code above in your browser using DataLab