From zero to hero
You mastered the skills of creating a model specification and splitting the data into training and test sets. You also know how to avoid class imbalances in the split. It's now time to combine what you learned in the preceding lesson and build your model using only the training set!
You are going to build a proper machine learning pipeline. This is comprised of creating a model specification, splitting your data into training and test sets, and last but not least, fitting the training data to a model. Enjoy!
This exercise is part of the course
Machine Learning with Tree-Based Models in R
Exercise instructions
- Create
diabetes_split
, a split where the training set contains three-quarters of alldiabetes
rows and where training and test sets have a similar distribution in theoutcome
variable. - Build a decision tree specification for your model using the
rpart
engine and save it astree_spec
. - Fit a model
model_trained
using the training data ofdiabetes_split
withoutcome
as the target variable andbmi
andskin_thickness
as the predictors.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
set.seed(9)
# Create the balanced data split
diabetes_split <- ___
# Build the specification of the model
tree_spec <- ___ %>%
___ %>%
___
# Train the model
model_trained <- ___ %>%
fit(___,
___)
model_trained