tidymodels / parsnip

A tidy unified interface to models
https://parsnip.tidymodels.org
Other
598 stars 89 forks source link

better error for unknown mode #186

Closed topepo closed 4 years ago

topepo commented 5 years ago

In the current devel version, mode is required for models that can fit classification or regression.

We need a better error message when it is left to be "unknown" when fit() or fit_xy() are run.

For example:

library(tidymodels)
#> Registered S3 methods overwritten by 'ggplot2':
#>   method         from 
#>   [.quosures     rlang
#>   c.quosures     rlang
#>   print.quosures rlang
#> Registered S3 method overwritten by 'xts':
#>   method     from
#>   as.zoo.xts zoo
#> ── Attaching packages ──────────────────────────────────────────────────────────────────────────────────────────────────── tidymodels 0.0.2 ──
#> ✔ broom     0.5.1          ✔ purrr     0.3.2     
#> ✔ dials     0.0.2          ✔ recipes   0.1.6     
#> ✔ dplyr     0.8.0.1        ✔ rsample   0.0.4     
#> ✔ ggplot2   3.1.1          ✔ tibble    2.1.3     
#> ✔ infer     0.4.0          ✔ yardstick 0.0.2     
#> ✔ parsnip   0.0.2.9000
#> ── Conflicts ─────────────────────────────────────────────────────────────────────────────────────────────────────── tidymodels_conflicts() ──
#> ✖ purrr::discard() masks scales::discard()
#> ✖ dplyr::filter()  masks stats::filter()
#> ✖ dplyr::lag()     masks stats::lag()
#> ✖ recipes::step()  masks stats::step()
library(randomForest)
#> randomForest 4.6-14
#> Type rfNews() to see new features/changes/bug fixes.
#> 
#> Attaching package: 'randomForest'
#> The following object is masked from 'package:ggplot2':
#> 
#>     margin
#> The following object is masked from 'package:dplyr':
#> 
#>     combine

rfp <- fit(
  parsnip::rand_forest(trees = 100) %>%  # no mode set
    parsnip::set_engine("randomForest"), 
  Species ~ ., data = iris
)
#> Error in fit.model_spec(parsnip::rand_forest(trees = 100) %>% parsnip::set_engine("randomForest"), : formula_ is unknown

Created on 2019-07-02 by the reprex package (v0.2.1)

patr1ckm commented 5 years ago

I think this was fixed in https://github.com/tidymodels/parsnip/pull/203/files and could be closed.

rand_forest(trees = 100) %>%
  set_engine("randomForest") %>%
  fit(Species ~ ., data = iris)

Now throws:

 Error: Please set the mode in the model specification. 
github-actions[bot] commented 3 years ago

This issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex: https://reprex.tidyverse.org) and link to this issue.