You can extract out the underlying model object (whether that was created by glm or ranger or keras or anything) from a parsnip object using $fit
.
library(tidymodels)
data(two_class_dat)
glm_spec <- logistic_reg() %>%
set_engine("glm")
norm_rec <- recipe(Class ~ A + B, data = two_class_dat) %>%
step_normalize(all_predictors())
glm_fit <- workflow() %>%
add_recipe(norm_rec) %>%
add_model(glm_spec) %>%
fit(two_class_dat) %>%
pull_workflow_fit()
What is in that fitted object?
## this is a parsnip object
glm_fit
#> parsnip model object
#>
#> Fit time: 5ms
#>
#> Call: stats::glm(formula = ..y ~ ., family = stats::binomial, data = data)
#>
#> Coefficients:
#> (Intercept) A B
#> -0.3491 -1.1063 2.7966
#>
#> Degrees of Freedom: 790 Total (i.e. Null); 788 Residual
#> Null Deviance: 1088
#> Residual Deviance: 673.9 AIC: 679.9
## this is a glm object
glm_fit$fit
#>
#> Call: stats::glm(formula = ..y ~ ., family = stats::binomial, data = data)
#>
#> Coefficients:
#> (Intercept) A B
#> -0.3491 -1.1063 2.7966
#>
#> Degrees of Freedom: 790 Total (i.e. Null); 788 Residual
#> Null Deviance: 1088
#> Residual Deviance: 673.9 AIC: 679.9
Created on 2021-02-04 by the reprex package (v1.0.0)
The fitted parameters will definitely not differ from calling the model directly. If you think you are finding different fitted parameters, then something may be going awry is how you are calling the model.