使用訓練/測試切分來訓練模型
你已經將 mpg 資料集切分為 mpg_train 與 mpg_test。現在要使用 mpg_train 來訓練一個模型,
用高速公路油耗(hwy)來預測市區油耗(cty)。
已為你載入 mpg_train 資料框。
本練習屬於課程
R 中的監督式學習:回歸
練習說明
- 建立一個公式
fmla,表示cty作為hwy的函式之關係。列印它。 - 使用
fmla與lm(),在mpg_train上訓練模型mpg_model,以hwy預測cty。 - 使用
summary()檢視模型。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# 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
___