使用類別型輸入建模
在這個練習中,你要對 flowers 資料配適一個線性模型,用 Time 和 Intensity 來預測 Flowers。
你在前一個練習建立的模型公式 fmla 仍可使用,模型矩陣 mmat 也同樣可用。
本練習屬於課程
R 中的監督式學習:回歸
練習說明
- 使用
fmla和lm訓練一個以Intensity與Time預測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")