nullmodel models

Function Works
tidypredict_fit(), tidypredict_sql(), parse_model()
tidypredict_to_column()
tidypredict_test()
tidypredict_interval(), tidypredict_sql_interval()
parsnip

parsnip::nullmodel() fits a model that ignores the predictors entirely. For regression it predicts the mean of the outcome, and for classification it predicts the observed class frequencies. Predictions are therefore constants, and tidypredict_fit() returns a plain number for regression and a named list of one constant per class for classification. Since the classification output is a list, tidypredict_to_column() and tidypredict_test() are only supported for regression.

tidypredict_ functions

model <- parsnip::nullmodel(mtcars[-1], mtcars$mpg)

For classification, one expression per class is returned:

c_model <- parsnip::nullmodel(iris[-5], iris$Species)

tidypredict_fit(c_model)
#> $setosa
#> [1] 0.3333333
#> 
#> $versicolor
#> [1] 0.3333333
#> 
#> $virginica
#> [1] 0.3333333

parsnip

parsnip fitted models are also supported by tidypredict:

library(parsnip)

p_model <- null_model(mode = "regression") %>%
  set_engine("parsnip") %>%
  fit(mpg ~ ., data = mtcars)
tidypredict_fit(p_model)
#> [1] 20.09062

Parse model spec

Here is an example of the model spec:

pm <- parse_model(model)
str(pm, 2)
#> List of 2
#>  $ general:List of 4
#>   ..$ model  : chr "nullmodel"
#>   ..$ version: num 2
#>   ..$ type   : chr "regression"
#>   ..$ is_glm : num 0
#>  $ terms  :List of 1
#>   ..$ :List of 4
#>  - attr(*, "class")= chr [1:3] "parsed_model" "pm_regression" "list"