Skip to content

Instantly share code, notes, and snippets.

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]])
}
replicates <- tibble::tribble(
~id, ~rep_1, ~rep_2,
"sample_001", 2.4061, 1.8369,
"sample_002", -0.6736, -0.102,
"sample_003", 1.0801, 0.7717,
"sample_004", 1.071, 1.5332,
"sample_005", 0.0674, 0.5275,
"sample_006", 1.6322, 1.8619,
"sample_007", -0.5528, -0.373,
"sample_008", 1.6413, 1.9207,
@topepo
topepo / flight_example.R
Created February 25, 2020 18:29
data analysis for nyc flights data set
library(tidymodels)
library(nycflights13)
set.seed(25213)
flight_data <-
flights %>%
mutate(
delay = ifelse(arr_delay >= 30, "late", "on_time"),
delay = factor(delay),
date = as.Date(time_hour)
@topepo
topepo / roc_shiny.R
Created December 5, 2019 21:02
shiny application for teaching ROC curves
library(shiny)
library(ggplot2)
library(dplyr)
library(yardstick)
theme_set(theme_bw())
n <- 1000
set.seed(124254)
@topepo
topepo / get_default_values.R
Created December 4, 2019 01:22
(try to) determine the default values for parsnip model arguments
get_default_values <- function(model, engine, mode) {
eng <- engine
mod_args <-
parsnip::get_from_env(paste0(model, "_args")) %>%
dplyr::filter(engine == eng)
model_fun <-
parsnip::get_from_env(paste0(model, "_fit")) %>%
dplyr::filter(engine == eng) %>%
dplyr::mutate(pkg = purrr::map_chr(value, ~ .x$func["pkg"]),
fun = purrr::map_chr(value, ~ .x$func["fun"]))