Machine learning with tidymodels
You can use the magrittr
%>% or base R
You are familiar with functions from dplyr, tidyr, ggplot2
You have exposure to basic statistical concepts
You do not need intermediate or expert familiarity with modeling or ML
Many thanks to Davis Vaughan, Julia Silge, David Robinson, Julie Jung, Alison Hill, and Desirée De Leon for their role in creating these materials!
🟪 “I’m stuck and need help!”
🟩 “I finished the exercise”
How are statistics and machine learning related?
How are they similar? Different?
library(tidymodels) #> ── Attaching packages ──────────────────────────── tidymodels 1.1.0 ── #> ✔ broom 1.0.5 ✔ rsample 1.1.1 #> ✔ dials 1.2.0 ✔ tibble 3.2.1 #> ✔ dplyr 1.1.2 ✔ tidyr 1.3.0 #> ✔ infer 1.0.4 ✔ tune 1.1.1 #> ✔ modeldata 1.1.0 ✔ workflows 1.1.3 #> ✔ parsnip 1.1.0 ✔ workflowsets 1.0.1 #> ✔ purrr 1.0.1 ✔ yardstick 1.2.0 #> ✔ recipes 1.0.6 #> ── Conflicts ─────────────────────────────── tidymodels_conflicts() ── #> ✖ purrr::discard() masks scales::discard() #> ✖ dplyr::filter() masks stats::filter() #> ✖ dplyr::lag() masks stats::lag() #> ✖ recipes::step() masks stats::step() #> • Learn how to get started at https://www.tidymodels.org/start/
Tomorrow we will walk through a case study in detail to illustrate feature engineering and model tuning.
Today we will walk through the analysis at a higher level to show the model development process as a whole and give you an introduction to the data set.
The data are from the NHL where we want to predict whether a shot was on-goal or not! 🏒
It’s a good example to show how model development works.
We’ll start by using basic logistic regression to predict our binary outcome.
Our first model will have 12 simple predictor columns.
One initial question: there are 632 players taking shots.
For logistic regression, do we convert these to binary indicators (a.k.a. “dummies”)?
The previous models used the x/y coordinates.
Are there better ways to represent shot location?
How can we make location more usable for the model?
Once we find an acceptable model and feature set, the process is to
If you are using your own laptop instead of RStudio Cloud:
broom (1.0.5, CRAN), DALEX (2.4.3, CRAN), DALEXtra (2.2.1, CRAN), dials (1.2.0, CRAN), doParallel (1.0.17, CRAN), dplyr (1.1.2, CRAN), embed (1.1.1, CRAN), ggplot2 (3.4.2, CRAN (R 4.2.1)), modeldata (1.1.0, CRAN), ongoal (0.0.4, Github (topepo/ongoal@2532b2404), parsnip (1.1.0, CRAN), purrr (1.0.1, CRAN), ranger (0.15.1, CRAN), recipes (1.0.6, CRAN), rpart (4.1.16, CRAN (R 4.2.1)), rpart.plot (3.1.1, CRAN), rsample (1.1.1, CRAN), scales (1.2.1, CRAN), stacks (1.0.2, CRAN), tibble (3.2.1, CRAN (R 4.2.1)), tidymodels (1.1.0, CRAN), tidyr (1.3.0, CRAN), tune (1.1.1, CRAN), vetiver (0.2.1, CRAN), workflows (1.1.3, CRAN), workflowsets (1.0.1, CRAN), xgboost (220.127.116.11, CRAN), and yardstick (1.2.0, CRAN)