Additional checks in set_mode
prevent improper use of model specs
#467
Labels
bug
an unexpected problem or unintended behavior
Feature
I want to preface this by saying I'm unsure if this is technically a bug or a feature request.
I think
parsnip
could benefit from adding an additional check inset_mode
to ensure that the user does not add an improper mode to a model Specification. For example, when initializing alinear_reg
specification, it will check ifmode
is eitherc("unknown", "regression")
:However, the user can still do
set_mode("classification")
without any warnings or errors.As a result, the user gets a really confusing downstream error when trying to use that "classification" model specification:
To someone who has just discovered
tidymodels
and has followed many online tutorials in which setting your mode withset_mode()
seems to be a common API practice, they would be under the impression thatmod2
is a perfectly acceptable model spec.I would imagine it isn't intended for users to add an incompatible mode to a model specification. So, adding something like the following function to validate proper spec modes might be desirable:
Incase the reader was curious, I found the source of the downstream error. The"
formula_
" comes from aswitch
statement infit.model_spec
, which is attributed to nofit$interface
existing onobject$method
. For example,add_method
is called, which then callsget_model_spec
, which is then unable to find a record inlinear_reg_fit
of a mode equivalent to "classification" and an engine of "lm".If the above check was in place, the user would have more feedback on how to use the model specification functions as they were intended. Similar to how
tidymodels
will not allow you to do a regression model where the outcome is a factor.If this is something the tidymodels team thinks should be added, I wouldn't mind starting a pull request.
The text was updated successfully, but these errors were encountered: