開始使用免費開始

使用類別型輸入建模

在這個練習中,你要對 flowers 資料配適一個線性模型,用 TimeIntensity 來預測 Flowers

你在前一個練習建立的模型公式 fmla 仍可使用,模型矩陣 mmat 也同樣可用。

本練習屬於課程

R 中的監督式學習:回歸

檢視課程

練習說明

  • 使用 fmlalm 訓練一個以 IntensityTime 預測 Flowers 的線性模型。將模型指定給變數 flower_model
  • 使用 summary() 回顧 mmat 的結構。
  • 使用 summary() 檢視 flower_model。這些變數是否與你在 mmat 中看到的相符?
  • 使用 flower_model 預測花朵數量,並將預測加入 flowers,欄位名稱為 predictions
  • 填入空格繪製「預測值 vs. 實際花朵數」的圖(x 軸為預測值)。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# flowers is available
str(flowers)

# fmla is available
fmla

# Fit a model to predict Flowers from Intensity and Time : flower_model
flower_model <- ___

# Use summary on mmat to remind yourself of its structure
___

# Use summary to examine flower_model 
___

# Predict the number of flowers on each plant
flowers$predictions <- ___

# Plot predictions vs actual flowers (predictions on x-axis)
ggplot(___, aes(x = ___, y = ___)) + 
  geom_point() +
  geom_abline(color = "blue") 
編輯並執行程式碼