Skip to content

Instantly share code, notes, and snippets.

@topepo
topepo / chicago_pls_dalex.R
Created July 30, 2020 03:16
Example code for using tidymodels, recipes, parsnip, and DALEX
library(tidymodels)
library(plsmod)
library(DALEX)
theme_set(theme_bw())
## ── Attaching packages ───────────────────────────────── tidymodels 0.1.1 ──
## ✓ broom 0.7.0 ✓ recipes 0.1.13
## ✓ dials 0.0.8 ✓ rsample 0.0.7
## ✓ dplyr 1.0.0 ✓ tibble 3.0.3
@topepo
topepo / component_plot.R
Created July 10, 2020 01:37
first of two S3 methods for plotting PCA components
#' @param x A prepped recipe or fitted workflow that uses a recipe. The recipe
#' must have used at least one `step_pca()`.
#' @param id A single numeric or character value that is used to pick the step
#' with the PCA results. If a single `step_pca()` was used, this argument is
#' ignored. *Note*: if used, `id` must be named.
#' @param ... An optional series of conditional statements used to filter the
#' PCA data before plotting. See Details below.
#' @examples
#' library(recipes)
#' library(parsnip)
## -----------------------------------------------------------------------------
# Simple demonstration of stacking using three models with the Ames housing data
## -----------------------------------------------------------------------------
library(tidymodels)
library(rules)
library(doMC)
library(AmesHousing)
library(ggforce)
library(tidymodels)
library(Matrix)
library(lobstr)
# ------------------------------------------------------------------------------
rand_values <- function (prefix = "step", len = 3, num_vals = Inf) {
candidates <- c(letters, LETTERS, paste(0:9))
candidates <- candidates[1:min(length(candidates), num_vals)]
library(tidyverse)
library(janitor)
library(tidymodels)
library(plotly)
theme_set(theme_bw())
body <-
read_csv("http://staff.pubhealth.ku.dk/~tag/Teaching/share/data/Bodyfat.csv") %>%
janitor::clean_names() %>%
library(tidyverse)
library(lubridate)
# ------------------------------------------------------------------------------
set.seed(2427)
hotels <-
readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2020/2020-02-11/hotels.csv') %>%
filter(is_canceled == 0) %>%
mutate(
# devtools::install_dev("rsample")
library(tidymodels)
set.seed(252)
first_split <- initial_split(iris, p = 8/10)
test <- testing(first_split)
nrow(test)
others <- training(first_split)
library(tidyverse)
library(lubridate)
theme_set(theme_bw())
dat <-
read_csv("https://raw.githubusercontent.com/nytimes/covid-19-data/master/us-counties.csv")
dat %>%
group_by(state) %>%
library(tidymodels)
library(modeldata)
data(attrition)
ord_rec <-
recipe(Attrition ~ JobInvolvement + JobSatisfaction, data = attrition) %>%
step_dummy(all_nominal()) %>%
prep() %>%
juice() %>%
library(tidymodels)
library(rlang)
get_arg <- function(ns, f, arg) {
args <- formals(getFromNamespace(f, ns))
args <- args %>% as.list()
as.character(args[[arg]])
}