Machine learning con mlr

Ottimizzazione degli iperparametri in R

Dr. Shirin Elsinghorst

Data Scientist

Il pacchetto mlr

  • mlr è un altro framework di machine learning in R.

L’addestramento segue tre passi:

  1. Definisci il task
  2. Definisci il learner
  3. Addestra il modello

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

Ottimizzazione degli iperparametri in R

Nuovo dataset: User Knowledge Data

library(tidyverse)
glimpse(knowledge_data)
Osservazioni: 150
Variabili: 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
Ottimizzazione degli iperparametri in R

Task in mlr per l’apprendimento supervisionato

  • RegrTask() per regressione
  • ClassifTask() per classificazione binaria e multiclasse
  • MultilabelTask() per problemi multi-etichetta
  • CostSensTask() per classificazione sensibile ai costi

 

Con il dataset sulla conoscenza degli studenti possiamo creare un classificatore:

task <- makeClassifTask(data = knowledge_train_data, 
                        target = "UNS")
Ottimizzazione degli iperparametri 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")
Ottimizzazione degli iperparametri in R

Addestrare un modello con 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
Ottimizzazione degli iperparametri in R

Ayo berlatih!

Ottimizzazione degli iperparametri in R

Preparing Video For Download...