Last updated 2025-09-04.
This Github repo contains all lesson files for Machine Learning in R.
The goal is to impart students with the basic tools to construct,
evaluate and compare various machine learning models, using
tidymodels
.
These topics were taught in the graduate-level course Machine Learning for Psychologists (Psych Dep., Ben-Gurion University of the Negev; Psych Dep., Tel-Aviv University). (Materials developed with Yael Bar-Shachar.) This course assumes basic competence in R (importing, regression modeling, plotting, etc.), along the lines of Practical Applications in R for Psychologists.
Notes:
- This repo contains only materials relating to Practical Applications in R, and does not contain any theoretical or introductory materials.
- Please note that some code does not work on purpose, to force students to learn to debug.
You will need:
- A fresh installation of
R
(preferably version 4.3.2 or above). - RStudio IDE (optional, but recommended).
- The following packages, listed by lesson:
Lesson | Packages |
---|---|
01 Intro with Regression | ISLR , tidymodels , stats , patchwork , kknn |
02 Classification | tidymodels , ISLR , stats , parameters , kknn , palmerpenguins , themis , patchwork , probably , tailor , modeldata |
03 Resampling and Tuning | tidymodels , kknn , finetune , ISLR , glue , modeldata , patchwork , datasets , tune , performance |
04 The problem of over-dimensionality | tidymodels , leaps , ISLR , stats , MASS , insight , glmnet , tidyr , scales , tibble , ggplot2 , vip , kknn , BiocManager , mixOmics , plsmod |
05 SVM | tidymodels , kernlab , ISLR , palmerpenguins |
06 Trees | tidymodels , rpart , rpart.plot , ISLR , scales , vip , MASS , tidymodels , baguette , randomForest , xgboost , MASS , forcats , vip |
07 explain predictions | tidymodels , kknn , randomForest , patchwork , DALEX , DALEXtra , marginaleffects , ISLR , palmerpenguins , vip |
08 unsupervised learning | tidyverse , patchwork , recipes , Rtsne , factoextra , ggrepel , cluster , randomForest , modeldata , psych , parameters , performance , datasets , GPArotation , dplyr , tidyr , psychTools |
Installing R Packages
You can install all the R packages used by running:
# in alphabetical order:
pak::pak(
c(
"cran::BiocManager" # 1.30.26
"cran::DALEX" # 2.5.2
"cran::DALEXtra" # 2.3.0
"cran::GPArotation" # 2025.3-1
"cran::ISLR" # 1.4
"cran::MASS" # 7.3-60.2
"cran::Rtsne" # 0.17
"cran::baguette" # 1.1.0
"cran::cluster" # 2.1.6
"cran::dplyr" # 1.1.4
"cran::factoextra" # 1.0.7
"cran::finetune" # 1.2.1
"cran::forcats" # 1.0.0
"cran::ggplot2" # 3.5.2
"cran::ggrepel" # 0.9.6
"cran::glmnet" # 4.1-10
"cran::glue" # 1.8.0
"cran::insight" # 1.4.1
"cran::kernlab" # 0.9-33
"cran::kknn" # 1.4.1
"cran::leaps" # 3.2
"cran::marginaleffects" # 0.29.0
"bioc::mixOmics" # 6.30.0
"cran::modeldata" # 1.5.1
"cran::palmerpenguins" # 0.1.1
"cran::parameters" # 0.28.0
"cran::patchwork" # 1.3.2
"cran::performance" # 0.15.0
"cran::plsmod" # 1.0.0
"cran::probably" # 1.1.1
"cran::psych" # 2.5.6
"cran::psychTools" # 2.5.7.22
"cran::randomForest" # 4.7-1.2
"github::tidymodels/recipes" # 1.3.1.9000
"cran::rpart" # 4.1.23
"cran::rpart.plot" # 3.1.3
"cran::scales" # 1.4.0
"cran::tailor" # 0.1.0
"cran::themis" # 1.0.3
"cran::tibble" # 3.3.0
"cran::tidymodels" # 1.3.0
"cran::tidyr" # 1.3.1
"cran::tidyverse" # 2.0.0
"github::tidymodels/tune" # 1.3.0.9001
"cran::vip" # 0.4.1
"cran::xgboost" # 1.7.11.1
)
)
Prior to 2025, this course was based on the {caret}
package - this
version can still be found
here.