Skip to main content

Machine Learning with tidymodels

Machine learning workflow in R using tidymodels, covering data partitioning, model fitting, cross-validation, model comparison, and hyperparameter tuning.
machine-learning
tidymodels
lecture
advanced
LearningLearning Objectives

After completing this session, you will be able to:

  • Explain the purpose of partitioning data into training, validation/assessment, and test sets, and describe why this practice helps prevent overfitting
  • Apply rsample::initial_split() and rsample::vfold_cv() to partition and resample a dataset
  • Construct classification models using parsnip, applying a consistent syntax across multiple algorithms
  • Evaluate model performance using appropriate classification metrics
  • Compare multiple model specifications and algorithms using cross-validated performance metrics to select a best-performing model.
  • Distinguish between model parameters and hyperparameters, and describe at a conceptual level how tuning strategies search hyperparameter space

1 Overview

Machine Learning (ML) is an intersection between statistics and computer science in which we train computers to learn directly from data without relying on hard-coded rules - identifying patterns, using those patterns to make predictions, then testing those predictions to refine future predictions. ML enables scientists to process, integrate, and analyze datasets across biological, environmental, and socioeconomic domains, helping identify ecological patterns and trends to inform conservation decisions.

Machine learning can range from “stats 101” concepts like linear regression and principal component analysis, to cutting-edge neural networks and transformer models that underpin social media recommendations, large language models, and generative AI.

In this lesson we will explore machine learning in R by applying the tidymodels framework to some relatively simple, intuitive datasets and algorithms.