Exporting parsnip model fit to pmml

I've searched far and wide but just not finding information. Is there a way to fit a model with the tidymodels set of packages (recipe, tune, rsample, tune...), fit the best model, and then export that model to a pmml format. I tinkered with the pmml package without any luck.

set.seed(123)

library(parsnip)
library(recipes)
#> Loading required package: dplyr
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
#> 
#> Attaching package: 'recipes'
#> The following object is masked from 'package:stats':
#> 
#>     step
library(workflows)
library(modeldata)

data("Sacramento")

base_wf <- workflow() %>%
  add_formula(price ~ type + sqft + beds + baths)

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

lm_fit <- base_wf %>%
  add_model(lm_spec) %>%
  fit(Sacramento)

library(pmml)
#> Loading required package: XML

lm_fit %>% extract_fit_parsnip() %>% pmml()
#> Error in UseMethod("pmml"): no applicable method for 'pmml' applied to an object of class "c('_lm', 'model_fit')"

Created on 2024-05-06 with reprex v2.1.0

tidymodels itself does not contain anything to convert models to PMML. That would be something to look for in a conversion package like pmml. pmml itself does not list parsnip models as supported but maybe the maintainer is open to a feature request?

Thanks - thinking of a different direction and using tidypredict but that seems not to incorporate recipes if you have that in your workflow.

Hello @StatSteph :wave:

I'm currently working on making {recipes} and thus {workflows} work with {tidypredict}. I don't have anything public yet. This action item does in fact have a timeline as I will be talking about it at Posit Conf :smiley:

1 Like

Oooh yay! I will be there - just registered last week.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.

The project allured to earlier is now public with https://orbital.tidymodels.org/.

So If this is still of interest, I would suggest you file an issue over there to have models translated to pmml.