Machine learning with mlr

Hyperparameter Tuning in R

Dr. Shirin Elsinghorst

Data Scientist

The mlr package

  • mlr is another framework for machine learning in R.

Model training follows three steps:

  1. Define the task
  2. Define the learner
  3. Fit the model

https://mlr-org.github.io/mlr

Hyperparameter Tuning in R

New dataset: User Knowledge Data

library(tidyverse)
glimpse(knowledge_data)
Observations: 150
Variables: 6
$ STG <dbl> 0.080, 0.000, 0.180, 0.100, 0.120, 0.090, 0.080, 0.150, ...
$ SCG <dbl> 0.080, 0.000, 0.180, 0.100, 0.120, 0.300, 0.325, 0.275, ...
$ STR <dbl> 0.100, 0.500, 0.550, 0.700, 0.750, 0.680, 0.620, 0.800, ...
$ LPR <dbl> 0.24, 0.20, 0.30, 0.15, 0.35, 0.18, 0.94, 0.21, 0.19, ...
$ PEG <dbl> 0.90, 0.85, 0.81, 0.90, 0.80, 0.85, 0.56, 0.81, 0.82, ...
$ UNS <chr> "High", "High", "High", "High", "High", "High", ...

 

knowledge_data %>%
    count(UNS)

 

# A tibble: 3 x 2
  UNS        n
  <chr>  <int>
1 High      50                                                         
2 Low       50
3 Middle    50
Hyperparameter Tuning in R

Tasks in mlr for supervised learning

  • RegrTask() for regression
  • ClassifTask() for binary and multi-class classification
  • MultilabelTask() for multi-label classification problems
  • CostSensTask() for general cost-sensitive classification

 

With our student knowledge dataset we can build a classifier:

task <- makeClassifTask(data = knowledge_train_data, 
                        target = "UNS")
Hyperparameter Tuning in R
listLearners()
                            class                   package
1                     classif.ada                 ada,rpart
2              classif.adaboostm1                     RWeka
3             classif.bartMachine               bartMachine
4                classif.binomial                     stats
5                classif.boosting              adabag,rpart
6                     classif.bst                 bst,rpart
7                     classif.C50                       C50
8                 classif.cforest                     party
9              classif.clusterSVM        SwarmSVM,LiblineaR
10                  classif.ctree                     party
...
# Define learner
lrn <- makeLearner("classif.h2o.deeplearning", 
                   fix.factors.prediction = TRUE,
                   predict.type = "prob")
Hyperparameter Tuning in R

Model fitting in mlr

tic()
# Define task
task <- makeClassifTask(data = knowledge_train_data, 
                        target = "UNS")
# Define learner
lrn <- makeLearner("classif.h2o.deeplearning",
                   fix.factors.prediction = TRUE)
# Fit model
model <- train(lrn, 
               task)
toc()
3.782 sec elapsed
Hyperparameter Tuning in R

Let's practice!

Hyperparameter Tuning in R

Preparing Video For Download...