Skip to content

make model package dependencies mode-specific #604

@topepo

Description

@topepo

parsnip registers required packages for a model/engine combination. The package list serves as a requirement for model fitting, prediction, and now deployment.

The problem: since the package dependency is not mode dependent, we will have extra packages that are installed and loaded for modes that do not need them. For example, if the censored package is loaded, the censored and pec packages are required for classification and regression models.

library(tidymodels)
#> Registered S3 method overwritten by 'tune':
#>   method                   from   
#>   required_pkgs.model_spec parsnip
library(censored)

decision_tree() %>% 
  set_mode("regression") %>% 
  req_pkgs()
#> [1] "censored" "pec"      "rpart"

Created on 2021-11-15 by the reprex package (v2.0.0)

This is also a problem when we are listing engine in the parsnip docs since there is no way to note that censored is required to use a particular mode.

Note that this has not been an issue to date since engines that work for multiple modes have had the same package dependencies. censored is changing that with the new "censored regression" mode.

An option can be added to set_dependency() for the mode the structure of the parsnip database for required packages would have a mode column. get_model_spec() should also be updated to make sure the correct packages are saved in the method slot when the model is fit. This would affect new models created with parsnip.

What about existing fitted models? These should be fine since there is not really an issue yet (pre-censored). Model specifications should also be fine since the methods slot is not yet populated.

req_pkg() (more specifically get_pkgs()) will also change to take into account the mode.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions