Apprentissage automatique avec mlr

Optimisation des hyperparamètres en R

Dr. Shirin Elsinghorst

Data Scientist

Le package mlr

  • mlr est un autre framework d’apprentissage automatique sous R.

L’entraînement suit trois étapes :

  1. Définir la tâche
  2. Définir l’apprenant
  3. Ajuster le modèle

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

Optimisation des hyperparamètres en R

Nouveau jeu de données : 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
Optimisation des hyperparamètres en R

Tâches mlr pour l’apprentissage supervisé

  • RegrTask() pour la régression
  • ClassifTask() pour la classification binaire et multiclasse
  • MultilabelTask() pour la classification multi‑étiquette
  • CostSensTask() pour la classification sensible aux coûts

 

Avec notre jeu de données sur les étudiants, on peut créer un classifieur :

task <- makeClassifTask(data = knowledge_train_data, 
                        target = "UNS")
Optimisation des hyperparamètres en 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")
Optimisation des hyperparamètres en R

Ajustement de modèle avec 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
Optimisation des hyperparamètres en R

Passons à la pratique !

Optimisation des hyperparamètres en R

Preparing Video For Download...