Train a model using test/train split
Now that you have split the mpg
dataset into mpg_train
and mpg_test
, you will use mpg_train
to train
a model to predict city fuel efficiency (cty
) from highway fuel efficiency (hwy
).
The mpg_train
data frame has been loaded for you.
This exercise is part of the course
Supervised Learning in R: Regression
Exercise instructions
- Create a formula
fmla
that expresses the relationshipcty
as a function ofhwy
. Print it. - Train a model
mpg_model
onmpg_train
to predictcty
fromhwy
usingfmla
andlm()
. - Use
summary()
to examine the model.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# mpg_train is available
summary(mpg_train)
# Create a formula to express cty as a function of hwy: fmla and print it.
(fmla <- ___)
# Now use lm() to build a model mpg_model from mpg_train that predicts cty from hwy
mpg_model <- ___
# Use summary() to examine the model
___