สร้างโมเดล linear regression
เมื่อสร้าง array ของ feature และ target แล้ว ขั้นตอนต่อไปคือการเทรนโมเดล linear regression โดยใช้ข้อมูลทั้งหมด
เนื่องจากเป้าหมายคือการวิเคราะห์ความสัมพันธ์ระหว่าง feature และ target จึงไม่จำเป็นต้องแบ่งข้อมูลเป็นชุด training และ test
X และ y ถูกโหลดไว้ให้แล้วดังนี้:
y = sales_df["sales"].values
X = sales_df["radio"].values.reshape(-1, 1)
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
Supervised Learning ด้วย scikit-learn
คำแนะนำการฝึกหัด
- Import
LinearRegression - สร้าง instance ของโมเดล linear regression
- ทำนายค่า sales โดยใช้
Xแล้วเก็บผลลัพธ์ไว้ในตัวแปรpredictions
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
# Import LinearRegression
from ____.____ import ____
# Create the model
reg = ____()
# Fit the model to the data
____
# Make predictions
predictions = ____
print(predictions[:5])