Skip to content

tidymodels/usemodels

main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
R
 
 
 
 
man
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

usemodels

R-CMD-check Coverage status lifecycle

The usemodels package is a helpful way of quickly creating code snippets to fit models using the tidymodels framework.

Given a simple formula and a data set, the use_* functions can create code that appropriate for the data (given the model).

For example, using the palmerpenguins data with a glmnet model:

> library(usemodels)
> library(palmerpenguins)
> data(penguins)
> use_glmnet(body_mass_g ~ ., data = penguins)
glmnet_recipe <- 
  recipe(formula = body_mass_g ~ ., data = penguins) %>% 
  step_novel(all_nominal_predictors()) %>% 
  step_dummy(all_nominal_predictors()) %>% 
  step_zv(all_predictors()) %>% 
  step_normalize(all_numeric_predictors()) 

glmnet_spec <- 
  linear_reg(penalty = tune(), mixture = tune()) %>% 
  set_mode("regression") %>% 
  set_engine("glmnet") 

glmnet_workflow <- 
  workflow() %>% 
  add_recipe(glmnet_recipe) %>% 
  add_model(glmnet_spec) 

glmnet_grid <- tidyr::crossing(penalty = 10^seq(-6, -1, length.out = 20), mixture = c(0.05, 
    0.2, 0.4, 0.6, 0.8, 1)) 

glmnet_tune <- 
  tune_grid(glmnet_workflow, resamples = stop("add your rsample object"), grid = glmnet_grid) 

The recipe steps that are used (if any) depend on the type of data as well as the model. In this case, the first two steps handle the fact that Species is a factor-encoded predictor (and glmnet requires all numeric predictors). The last two steps are added because, for this model, the predictors should be on the same scale to be properly regularized.

The package includes these templates:

> ls("package:usemodels", pattern = "use_")
 [1] "use_bag_tree_rpart"   "use_C5.0"             "use_cubist"          
 [4] "use_dbarts"           "use_earth"            "use_glmnet"          
 [7] "use_kernlab_svm_poly" "use_kernlab_svm_rbf"  "use_kknn"            
[10] "use_mgcv"             "use_mixOmics"         "use_nnet"            
[13] "use_ranger"           "use_rpart"            "use_xgboost"         
[16] "use_xrf"             

You can also copy code to the clipboard using the option clipboard = TRUE.

Installation

You can install usemodels with:

devtools::install_github("tidymodels/usemodels")

Contributing

This project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.

About

Boilerplate Code for tidymodels

Resources

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages