R Tutorial: Recap of machine learning basics
Key Takeaways
The video covers the basics of machine learning in R using the caret package, including data partitioning, hyperparameter tuning, and model training. It demonstrates how to use caret to automatically perform hyperparameter tuning and train a random forest model.
Full Transcript
good job you now have a solid understanding of the differences between model parameters and hyper parameters but Before we jump into actively tuning the hyper parameters we will briefly recap the basics of machine learning in art we will use the carrot package first because it automatically performs a basic hyper parameter tuning for you with every training run but before we look into this automatic high parameter tuning in carrot we need to prepare our data for training first we will divide our data into training and test sets carrot makes the step easy with the create data partition function let us give a class label vector as input for stratified partitioning of the data this is important because we want to have a roughly equal ratio of classes in our training and test set with the argument P we tell the function what proportion of the data should go into the training set here 70% the index that will be created can then be used for sub setting the original data set how much of the data you want to keep for training can be part of the optimization process there are really no strict rules on how to split the data but you want to make sure that you have enough training power and that you have a representative tested with a small data set such as this 70% is a common number but you will also often see 80 or 90% training data here I will not go into additional steps of the machine learning workflow like feature engineering pre-processing normalization balancing classes etc just keep in mind that in a real world scenario you would at least want to think about incorporating these steps into your workflow our validations team is defined in the train control function we will do five times three repeated cross-validation which means repeating three fold cross validation five times this scheme is then given as an argument in the train function in carrot we can train machine learning models with a large number of different algorithms we define this with the argument method in the train function here we will train a random forest model which is abbreviated our F train also wants to know which data in which feature to use our data set is the training set that we created before the features are given with a formula the class or response variable here diagnosis is written before and features after the tilly for features we write in dot here which indicates that we want to use all remaining columns as features in our model in addition I want to know how long my model took to Train for this I am using the tick-tock package which will return the run time between tick and tock as we can see our model took about 1.4 seconds to Train here is the random forest model we just trained in the output we can already see hyper parameter tuning and action as carrot performs it automatically with every option for the hyper parameter M try you will learn more about that in the next lesson what's important to note here is that carrot compares different a parameter on the training and validation data only do not be tempted to measure your model performance on the test data during hyper parameter tuning as that would give you an overly optimistic and biased performance evaluation now it's your turn
Original Description
Want to learn more? Take the full course at https://learn.datacamp.com/courses/hyperparameter-tuning-in-r at your own pace. More than a video, you'll learn hands-on coding & quickly apply skills to your daily work.
---
Good job, you now have a solid understanding of the differences between model parameters and hyperparameters.
But before we jump into actively tuning the hyperparameters, we will briefly recap the basics of machine learning in R.
We will use the caret package first, because it automatically performs a basic hyperparameter tuning for you with every training run.
But before we look into this automatic hyperparameter tuning in caret, we need to prepare our data for training.
First, we will divide our data into training and test sets.
Caret makes this step easy with the `createDataPartition` function. It lets us give a class label vector as input for stratified partitioning of the data; this is important because we want to have a roughly equal ratio of classes in our training and test set. With the argument `p` we tell the function what proportion of the data should go into the training set, here 70%.
The index that will be created can then be used for subsetting the original dataset.
How much of the data you want to keep for training can be part of the optimization process. There are really no strict rules on how to split the data but you want to make sure that you have enough training power
and that you have a representative test set. With a small dataset such as this, 70% is a common number, but you will also often see 80 or 90% training data.
Here, I will not go into additional steps of the machine learning workflow, like feature engineering, preprocessing, normalization, balancing classes, etc. Just keep in mind that in a real-world scenario, you would at least want to think about incorporating these steps into your workflow.
Our validation scheme is defined in the `trainControl()` function: we will do 5 times 3 repeated cross-validatio
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from DataCamp · DataCamp · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
SQL Server Tutorial: Date manipulation
DataCamp
R Tutorial: Intermediate Interactive Data Visualization with plotly in R
DataCamp
R Tutorial: Adding aesthetics to represent a variable
DataCamp
R Tutorial: Moving Beyond Simple Interactivity
DataCamp
Python Tutorial: Why use ML for marketing? Strategies and use cases
DataCamp
Python Tutorial: Preparation for modeling
DataCamp
Python Tutorial: Machine Learning modeling steps
DataCamp
R Tutorial: The prior model
DataCamp
R Tutorial: Data & the likelihood
DataCamp
R Tutorial: The posterior model
DataCamp
R Tutorial: An Introduction to plotly
DataCamp
R Tutorial: Plotting a single variable
DataCamp
R Tutorial: Bivariate graphics
DataCamp
Python Tutorial: Customer Segmentation in Python
DataCamp
Python Tutorial: Time cohorts
DataCamp
Python Tutorial: Calculate cohort metrics
DataCamp
Python Tutorial: Cohort analysis visualization
DataCamp
R Tutorial: Building Dashboards with flexdashboard
DataCamp
R Tutorial: Anatomy of a flexdashboard
DataCamp
R Tutorial: Layout basics
DataCamp
R Tutorial: Advanced layouts
DataCamp
Python Tutorial: Time Series Analysis in Python
DataCamp
Python Tutorial: Correlation of Two Time Series
DataCamp
Python Tutorial: Simple Linear Regressions
DataCamp
Python Tutorial: Autocorrelation
DataCamp
R Tutorial: The gapminder dataset
DataCamp
R Tutorial: The filter verb
DataCamp
R Tutorial: The arrange verb
DataCamp
R Tutorial: The mutate verb
DataCamp
R Tutorial: What is cluster analysis?
DataCamp
R Tutorial: Distance between two observations
DataCamp
R Tutorial: The importance of scale
DataCamp
R Tutorial: Measuring distance for categorical data
DataCamp
Python Tutorial: Plotting multiple graphs
DataCamp
Python Tutorial: Customizing axes
DataCamp
Python Tutorial: Legends, annotations, & styles
DataCamp
Python Tutorial: Introduction to iterators
DataCamp
Python Tutorial: Playing with iterators
DataCamp
Python Tutorial: Using iterators to load large files into memory
DataCamp
SQL Tutorial: Introduction to Relational Databases in SQL
DataCamp
SQL Tutorial: Tables: At the core of every database
DataCamp
SQL Tutorial: Update your database as the structure changes
DataCamp
Python Tutorial: Classification-Tree Learning
DataCamp
Python Tutorial: Decision-Tree for Classification
DataCamp
Python Tutorial: Decision-Tree for Regression
DataCamp
Python Tutorial: Census Subject Tables
DataCamp
Python Tutorial: Census Geography
DataCamp
Python Tutorial: Using the Census API
DataCamp
R Tutorial: A/B Testing in R
DataCamp
R Tutorial: Baseline Conversion Rates
DataCamp
R Tutorial: Designing an Experiment - Power Analysis
DataCamp
R Tutorial: Introduction to qualitative data
DataCamp
R Tutorial: Understanding your qualitative variables
DataCamp
R Tutorial: Making Better Plots
DataCamp
SQL Tutorial: OLTP and OLAP
DataCamp
SQL Tutorial: Storing data
DataCamp
SQL Tutorial: Database design
DataCamp
Python Tutorial: Introduction to spaCy
DataCamp
Python Tutorial: Statistical Models
DataCamp
Python Tutorial: Rule-based Matching
DataCamp
More on: ML Pipelines
View skill →Related Reads
📰
📰
📰
📰
Clipdrop vs Runway vs Kling: Which is Best for Drama in 2026?
Dev.to AI
The Ultimate Guide to Crafting a Stellar Resume with AI Technology
Dev.to AI
Observability Design for the AI Era — Application / Infrastructure / CI / LLM, Each in Its Own Shape (Part 1)
Dev.to · Ryosuke Tsuji
The AI Resource I Could Never Find — So I Decided to Build It
Medium · AI
🎓
Tutor Explanation
DeepCamp AI