fda models

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

mda::fda() fits flexible discriminant analysis models. Predicting with such a model runs the predictors through a regression fit, projects the result onto the discriminant variates, and turns the distance to each class centroid into a posterior probability. When the regression fit is linear in the predictors, the whole path collapses into one linear predictor per outcome class and the posterior probabilities are the softmax of those linear predictors.

That restricts support to the two linear regression methods: mda::polyreg() (the default) with degree = 1, and mda::gen.ridge(), which is what discrim_linear() uses. Higher polynomial degrees and the mda::mars() and mda::bruto() methods are not supported, and neither are the mixture models from mda::mda().

Because these models predict one probability per outcome class, tidypredict_fit() returns a named list of expressions, one for each class, rather than a single expression. Since the output is a list, tidypredict_to_column() and tidypredict_test() are not supported.

tidypredict_ functions

model <- mda::fda(Species ~ ., data = iris)

parsnip

parsnip fitted models are also supported by tidypredict:

library(parsnip)
library(discrim)

p_model <- discrim_linear(penalty = 1) %>%
  set_engine("mda") %>%
  fit(Species ~ ., data = iris)
tidypredict_fit(p_model)[["virginica"]]
#> 1/(exp(-11.9575128198861 + (Sepal.Length * 5.80316342827773) + 
#>     (Sepal.Width * 10.802899579644) + (Petal.Length * -16.5217691675749) + 
#>     (Petal.Width * -17.3381617005549) - (-33.2183837927994 + 
#>     (Sepal.Length * -4.41029984072505) + (Sepal.Width * -6.75173810807833) + 
#>     (Petal.Length * 12.0386389001348) + (Petal.Width * 14.7915580954519))) + 
#>     exp(-2.27975663240432 + (Sepal.Length * -1.39286358755267) + 
#>         (Sepal.Width * -4.05116147156562) + (Petal.Length * 4.48313026744007) + 
#>         (Petal.Width * 2.546603605103) - (-33.2183837927994 + 
#>         (Sepal.Length * -4.41029984072505) + (Sepal.Width * -6.75173810807833) + 
#>         (Petal.Length * 12.0386389001348) + (Petal.Width * 14.7915580954519))) + 
#>     1)

Parse model spec

Here is an example of the model spec:

pm <- parse_model(model)
str(pm, 2)
#> List of 3
#>  $ general    :List of 4
#>   ..$ model  : chr "fda"
#>   ..$ version: num 2
#>   ..$ type   : chr "multiclass_regression"
#>   ..$ family : chr "multinomial"
#>  $ classes    : chr [1:3] "setosa" "versicolor" "virginica"
#>  $ class_terms:List of 3
#>   ..$ :List of 5
#>   ..$ :List of 5
#>   ..$ :List of 5
#>  - attr(*, "class")= chr [1:3] "parsed_model" "pm_multiclass_regression" "list"