開始使用免費開始

使用訓練/測試切分來訓練模型

你已經將 mpg 資料集切分為 mpg_trainmpg_test。現在要使用 mpg_train 來訓練一個模型, 用高速公路油耗(hwy)來預測市區油耗(cty)。

已為你載入 mpg_train 資料框。

本練習屬於課程

R 中的監督式學習:回歸

檢視課程

練習說明

  • 建立一個公式 fmla,表示 cty 作為 hwy 的函式之關係。列印它。
  • 使用 fmlalm(),在 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
___
編輯並執行程式碼