การสร้างโมเดลด้วย input ประเภท categorical
ในแบบฝึกหัดนี้ จะฝึกสร้างโมเดลเชิงเส้นกับข้อมูล flowers เพื่อทำนาย Flowers จาก Time และ Intensity
สูตรโมเดล fmla ที่สร้างไว้ในแบบฝึกหัดก่อนหน้ายังคงพร้อมใช้งาน เช่นเดียวกับ model matrix mmat
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
Supervised Learning ใน R: การถดถอย
คำแนะนำการฝึกหัด
- ใช้
fmlaและlmเพื่อ train โมเดลเชิงเส้นที่ทำนายFlowersจากIntensityและTimeแล้วกำหนดโมเดลให้กับตัวแปรflower_model - ใช้
summary()เพื่อทบทวนโครงสร้างของmmat - ใช้
summary()เพื่อตรวจสอบflower_modelว่าตัวแปรตรงกับที่เห็นในmmatหรือไม่ - ใช้
flower_modelทำนายจำนวนดอกไม้ แล้วเพิ่มค่าที่ทำนายได้ลงในflowersในชื่อคอลัมน์predictions - เติมช่องว่างเพื่อพล็อตกราฟเปรียบเทียบค่าที่ทำนายกับจำนวนดอกไม้จริง (โดยให้ค่าทำนายอยู่บนแกน 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")