เริ่มต้นใช้งานเริ่มต้นใช้งานได้ฟรี

สร้างและประเมินโมเดลที่ดีที่สุด

จากการใช้ cross-validation คุณสามารถระบุโมเดลที่ดีที่สุดสำหรับการทำนาย life_expectancy โดยใช้ฟีเจอร์ทั้งหมดใน gapminder ได้แล้ว เมื่อเลือกโมเดลได้แล้ว ให้นำชุดข้อมูลอิสระ (testing_data) ที่สำรองไว้มาใช้ประเมินประสิทธิภาพของโมเดลกับข้อมูลใหม่

คุณจะสร้างโมเดลนี้โดยใช้ข้อมูลทั้งหมดใน training_data และประเมินผลด้วย testing_data

แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร

Machine Learning ใน Tidyverse

ดูคอร์ส

คำแนะนำการฝึกหัด

  • ใช้ ranger() เพื่อสร้างโมเดลที่มีประสิทธิภาพสูงสุด (mtry = 4) โดยใช้ข้อมูล training ทั้งหมด แล้วกำหนดให้กับ best_model
  • ดึงคอลัมน์ life_expectancy จาก testing_data แล้วกำหนดให้กับ test_actual
  • ทำนาย life_expectancy โดยใช้ best_model กับข้อมูล testing แล้วกำหนดให้กับ test_predicted
  • คำนวณค่า MAE โดยใช้เวกเตอร์ test_actual และ test_predicted

แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ

ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์

# Build the model using all training data and the best performing parameter
best_model <- ranger(formula = ___, data = ___,
                     mtry = ___, num.trees = 100, seed = 42)

# Prepare the test_actual vector
test_actual <- testing_data$___

# Predict life_expectancy for the testing_data
test_predicted <- predict(___, ___)$predictions

# Calculate the test MAE
mae(___, ___)
แก้ไขและรันโค้ด