6.4 {tidymodels}-Adjacent Packages

  • Opinions can be shared, other modeling packages can use the same opinion to replicate a workflow. The {discrim}2 package adds a new set of mathematical models to our arsenal of tools.
    • discrim_flexible() %>% - Mathematical Model or if we are using my terrible analogy the car body
      • set_engine("earth") - The package we want to approximate our discriminat analysis
# devtools::install_github("tidymodels/discrim") # to install
# load package
library(discrim)

# create dummy data
parabolic_grid <-
  expand.grid(X1 = seq(-5, 5, length = 100),
              X2 = seq(-5, 5, length = 100))

# fit model from discrim
fda_mod <-
  discrim_flexible(num_terms = 3) %>% 
  set_engine("earth") %>%
  fit(class ~ ., data = parabolic)

# assigning predictions to data frame
parabolic_grid$fda <-
  predict(fda_mod, parabolic_grid, type = "prob")$.pred_Class1

# plotting prediction
library(ggplot2)
ggplot(parabolic, aes(x = X1, y = X2)) +
  geom_point(aes(col = class), alpha = .5) +
  geom_contour(data = parabolic_grid, aes(z = fda), col = "black", breaks = .5) +
  theme_bw() +
  theme(legend.position = "top") +
  coord_equal()


  1. Discrim Package Link↩︎