The hardware and bandwidth for this mirror is donated by METANET, the Webhosting and Full Service-Cloud Provider.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]metanet.ch.

sda models

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

sda::sda() fits shrinkage discriminant analysis models, including the diagonal variant (diagonal = TRUE). Predicting with such a model is a softmax over one linear predictor per outcome class, so 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.

Only the features that survive shrinkage appear in the fitted model, and the generated expressions reference just those.

tidypredict_ functions

model <- sda::sda(as.matrix(iris[1:4]), iris$Species, verbose = FALSE)

sda() rounds its posterior probabilities with zapsmall(), so expect agreement to about seven decimal places rather than exactly.

parsnip

parsnip fitted models are also supported by tidypredict:

library(parsnip)
library(discrim)

p_model <- discrim_linear() %>%
  set_engine("sda") %>%
  fit(Species ~ ., data = iris)
tidypredict_fit(p_model)[["virginica"]]
#> 1/(exp(-13.1507094677663 + (Sepal.Length * 5.73266109594567) + 
#>     (Sepal.Width * 11.3604293693888) + (Petal.Length * -16.8084846238172) + 
#>     (Petal.Width * -16.6240117338794) - (-32.2372116751415 + 
#>     (Sepal.Length * -4.34938531801267) + (Sepal.Width * -7.15408886770749) + 
#>     (Petal.Length * 12.2374234168127) + (Petal.Width * 14.1269553854408))) + 
#>     exp(-2.17403913501321 + (Sepal.Length * -1.38327577793295) + 
#>         (Sepal.Width * -4.20634050168117) + (Petal.Length * 4.57106120700443) + 
#>         (Petal.Width * 2.49705634843863) - (-32.2372116751415 + 
#>         (Sepal.Length * -4.34938531801267) + (Sepal.Width * -7.15408886770749) + 
#>         (Petal.Length * 12.2374234168127) + (Petal.Width * 14.1269553854408))) + 
#>     1)

sda() is fit from a numeric matrix, so a model fit directly can only refer to the matrix columns it was given. Categorical predictors therefore work through the parsnip interface, which keeps the formula around and lets the dummy columns be written in terms of the original factors:

cars <- transform(mtcars, cyl = factor(cyl), gear = factor(gear))

c_model <- discrim_linear() %>%
  set_engine("sda") %>%
  fit(cyl ~ mpg + gear + disp, data = cars)

tidypredict_fit(c_model)[["8"]]
#> 1/(exp(-5.90478040863942 + (mpg * 0.450539182424721) + (ifelse(gear == 
#>     "4", 1, 0) * 0.120334811858768) + (ifelse(gear == "5", 1, 
#>     0) * -0.326397688436066) + (disp * -0.0361970033802603) - 
#>     (-9.69338951858341 + (mpg * -0.300898442298614) + (ifelse(gear == 
#>         "4", 1, 0) * -0.28874400106328) + (ifelse(gear == "5", 
#>         1, 0) * 0.34679228046224) + (disp * 0.0491641125277206))) + 
#>     exp(4.82341069251291 + (mpg * -0.145463097730621) + (ifelse(gear == 
#>         "4", 1, 0) * 0.189561232611213) + (ifelse(gear == "5", 
#>         1, 0) * -0.0358060646840223) + (disp * -0.0157055813201664) - 
#>         (-9.69338951858341 + (mpg * -0.300898442298614) + (ifelse(gear == 
#>             "4", 1, 0) * -0.28874400106328) + (ifelse(gear == 
#>             "5", 1, 0) * 0.34679228046224) + (disp * 0.0491641125277206))) + 
#>     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 "sda"
#>   ..$ 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"

These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.