Polo
Polo

Reputation: 43

Verify model assumptions with tidymodels

Outside of the tidymodels universe, it's easy to verify model assumptions. For example with linear regression (function lm), the package performance create understandable graphics and easy functions (check_heteroscedasticity()) to verify assumptions of a linear regression model :

Is there in the tidymodels universe equivalent packages to verify assumptions of a model ? Tidymodels packages create parnsnip object, so old model evaluation packages like performance are useless.

Thank you for your help

Upvotes: 4

Views: 1220

Answers (1)

EmilHvitfeldt
EmilHvitfeldt

Reputation: 3185

The fitted models you get from using {parsnip} or other {tidymodels} will contain the underlying fitted model for whatever engine you are using.

Sometimes the fitted parsnip object will work directly with the function you are using. This is the case with the check_model() function from {performance}.

library(tidymodels)
library(performance)

lm_spec <- linear_reg() %>%
  set_mode("regression") %>%
  set_engine("lm")

lm_fit <- fit(lm_spec, mpg ~ ., data = mtcars)

lm_fit %>%
  check_model()

Other times you will get an error because the function doesn't know what to do with a model_fit object. You can use the extract_fit_engine() which will extract the fit produced by the engine, that can then be used with check_heteroscedasticity().

lm_fit %>% 
  extract_fit_engine() %>%
  check_heteroscedasticity()
#> OK: Error variance appears to be homoscedastic (p = 0.188).

Created on 2021-09-06 by the reprex package (v2.0.1)

Upvotes: 9

Related Questions