ปรับความแรงของ Regularization
โมเดล Lasso ที่ใช้อยู่ตอนนี้มีคะแนน \(R^2\) อยู่ที่ 84.7% เมื่อโมเดลใช้ Regularization ที่แรงเกินไป อาจเกิด High Bias ซึ่งส่งผลให้ความสามารถในการพยากรณ์ลดลง
มาปรับสมดุลระหว่างประสิทธิภาพการพยากรณ์และความเรียบง่ายของโมเดลด้วยการปรับพารามิเตอร์ alpha กัน
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
การลดมิติข้อมูลใน Python
คำแนะนำการฝึกหัด
- หาค่า สูงสุด ของ
alphaที่ยังให้ค่า \(R^2\) เกิน 98% จากตัวเลือกต่อไปนี้:1,0.5,0.1และ0.01
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
# Find the highest alpha value with R-squared above 98%
la = Lasso(____, random_state=0)
# Fits the model and calculates performance stats
la.fit(X_train_std, y_train)
r_squared = la.score(X_test_std, y_test)
n_ignored_features = sum(la.coef_ == 0)
# Print peformance stats
print(f"The model can predict {r_squared:.1%} of the variance in the test set.")
print(f"{n_ignored_features} out of {len(la.coef_)} features were ignored.")