High-Level Modeling Functions with 'torch'

Provides high-level modeling functions to define and train models using the 'torch' R package. Models include linear, logistic, and multinomial regression, multilayer perceptrons, modern neural neural networks, and the pretrained tabular foundational models such as 'TabICL' and 'TabPFN'.


brulee a dish of creme brulee on a striped background

R-CMD-check Lifecycle: experimental Codecov test coverage

The R brulee package contains several basic modeling functions that use the torch package infrastructure, such as:

Chronos2, TabICL, and TabPFN are pretrained models that need a one-time download of their weights: about 480MB for Chronos2, 225MB for TabICL (both tasks), and, for TabPFN, 880MB for the default version 3.5 (330MB for 3.5-fast and 450MB for 3).

Installation

You can install the released version of brulee from CRAN with:

install.packages("brulee")

And the development version from GitHub with:

# install.packages("pak")
pak::pak("tidymodels/brulee")

Example

brulee has formula, x/y, and recipe user interfaces for each function. For example:

library(brulee)
library(recipes)
library(yardstick)

data(bivariate, package = "modeldata")
set.seed(20)
nn_log_biv <- brulee_mlp(Class ~ log(A) + log(B), data = bivariate_train, 
                         hidden_units = 3)

# We use the tidymodels semantics to always return a tibble when predicting
predict(nn_log_biv, bivariate_test, type = "prob") 
#> # A tibble: 710 × 2
#>    .pred_One .pred_Two
#>        <dbl>     <dbl>
#>  1     0.675     0.325
#>  2     0.673     0.327
#>  3     0.679     0.321
#>  4     0.688     0.312
#>  5     0.685     0.315
#>  6     0.679     0.321
#>  7     0.674     0.326
#>  8     0.681     0.319
#>  9     0.697     0.303
#> 10     0.675     0.325
#> # ℹ 700 more rows

A recipe can also be used if the data require some sort of preprocessing (e.g., indicator variables, transformations, or standardization):

library(recipes)

rec <- 
  recipe(Class ~ ., data = bivariate_train) |>  
  step_YeoJohnson(all_numeric_predictors()) |> 
  step_normalize(all_numeric_predictors())

set.seed(20)
nn_rec_biv <- brulee_mlp(rec, data = bivariate_train, 
                         epochs = 150, hidden_units = 3)

# A little better
predict(nn_rec_biv, bivariate_test, type = "prob") |> 
  bind_cols(bivariate_test) |> 
  roc_auc(Class, .pred_One)
#> # A tibble: 1 × 3
#>   .metric .estimator .estimate
#>   <chr>   <chr>          <dbl>
#> 1 roc_auc binary         0.867

Code of Conduct

Please note that the brulee project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("brulee")

1.3.0 by Max Kuhn, 6 days ago


https://github.com/tidymodels/brulee, https://brulee.tidymodels.org/


Report a bug at https://github.com/tidymodels/brulee/issues


Browse source code at https://github.com/cran/brulee


Authors: Max Kuhn [aut, cre] , Daniel Falbel [aut] , Posit Software , PBC [cph, fnd] , Prior Labs GmbH [cph] (TabPFN code ported from the Python 'tabpfn' package; see inst/COPYRIGHTS)


Documentation:   PDF Manual  


MIT + file LICENSE license


Imports cli, coro, curl, dplyr, generics, ggplot2, hardhat, jsonlite, purrr, rlang, safetensors, stats, tibble, tidyselect, torch, utils, withr

Suggests covr, lubridate, modeldata, recipes, spelling, testthat, yardstick


Suggested by MLwrap, orbital, tabby, tidyAML.


See at CRAN