Skip to content

Commit

Permalink
add faq entries (#165)
Browse files Browse the repository at this point in the history
* migrates the mlr3 wiki FAQ
* add FAQ on how to use an old mlr3 model
  • Loading branch information
sebffischer committed Aug 18, 2024
1 parent 700122b commit cc481d3
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions mlr-org/faq.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ title: Frequently Asked Questions
* [Preprocessing factor levels](#factor-levels)
* [Memory Problems](#memory-problems)
* [How can I suppress logging output of learners on the R console](#suppress-output)
* [A learner trained with an old mlr3 version does not work anymore](#old-model-broken)
* [Caching of knitr/rmarkdown chunks does not work with mlr3](#caching-knitr)
* [How to keep all mlr3 packages up-to-date?](#update-packages)

## Why is there only the rpart learner? {#learner}

Expand Down Expand Up @@ -102,3 +105,53 @@ mylearner$encapsulate = c(train = "evaluate", predict = "evaluate")
mylearner$train(mytask)
```

## A learner trained with an old mlr3 version does not work anymore {#old-model-broken}

It is possible that a saved `Learner` that was trained with an old `mlr3` version does not work with a different version of `mlr3`.
In general, we recommend saving the computational environment using a tool like [renv](https://github.com/rstudio/renv) so this can later be restored and avoiding such situations alltogether.
If this is not an option, a possible workaround is to construct the same learner in the currently used `mlr3` version and manually set its `$state` to the one of the saved learner.
This is illustrated below:

1. Using an old `mlr3` version:

```{r, eval = FALSE}
learner = lrn("classif.rpart")
learner$train(tsk("iris"))
saveRDS(learner, "learner.rds")
```

1. With a subsequent `mlr3` version:

```{r, eval = FALSE}
learner = lrn("classif.rpart")
learner_old = readRDS("learner.rds")
learner$state = learner_old$state
```

Note that this is **risky** and **not** guaranteed to work because of various reasons:
* You might have now loaded a different version of the learner library (in this case the `rpart` pacakge).
* The internals (such as the structure of the internal `$state`) might have changed between the versions.

Therefore, be careful when attempting this solution and double-check that the learner behaves sensibly.

## Caching of knitr/rmarkdown chunks does not work with mlr3 {#caching-knitr}

{knitr} per default uses R's lazy-load database to store the results of individual chunks.
The lazy-load database is an internal feature of R, and has issues handling active bindings ([https://github.com/r-lib/R6/issues/152](https://github.com/r-lib/R6/issues/152)).
Fortunately, it is possible to disable lazy-loading by setting the chunk option `cache.lazy` to `FALSE`:

```{r, eval = FALSE}
knitr::opts_chunk$set(cache = TRUE, cache.lazy = FALSE)
```

## How to keep all mlr3 packages up-to-date? {#update-packages}

Either run R's `update.packages()` to update all installed packages, or run

```r
devtools::update_packages("mlr3verse", dependencies = TRUE)
```

to update only packages from the mlr3verse.
Note that this also updates recursive dependencies not listed as a direct import.

0 comments on commit cc481d3

Please sign in to comment.