Get startedGet started for free

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

View Course

Exercise instructions

  • Create a formula fmla that expresses the relationship cty as a function of hwy. Print it.
  • Train a model mpg_model on mpg_train to predict cty from hwy using fmla and lm().
  • 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
___
Edit and Run Code