การแสดงค่าสัมประสิทธิ์และ intercept
เมื่อโมเดล logistic regression พร้อมใช้งานแล้ว การตรวจสอบค่าสัมประสิทธิ์เป็นสิ่งที่น่าสนใจ เพราะช่วยให้เข้าใจได้ว่าโมเดลมีความสมเหตุสมผลหรือไม่
สำหรับโมเดล logistic regression ที่ฝึกแล้วชื่อ logreg สามารถดึงค่าสัมประสิทธิ์ได้โดยใช้แอตทริบิวต์ coef_ โดยลำดับของค่าสัมประสิทธิ์จะตรงกับลำดับของตัวแปรที่ป้อนเข้าโมเดล ส่วนค่า intercept สามารถดึงได้โดยใช้แอตทริบิวต์ intercept_
โมเดล logistic regression ที่สร้างไว้ในแบบฝึกหัดก่อนหน้าได้ถูกเพิ่มและฝึกไว้ให้แล้วใน logreg
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
การวิเคราะห์เชิงพยากรณ์เบื้องต้นด้วย Python
คำแนะนำการฝึกหัด
- กำหนดค่าสัมประสิทธิ์ของโมเดล logistic regression ให้กับลิสต์
coef - กำหนดค่า intercept ของโมเดล logistic regression ให้กับตัวแปร
intercept
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
# Construct a logistic regression model that predicts the target using age, gender_F and time_since_last gift
predictors = ["age","gender_F","time_since_last_gift"]
X = basetable[predictors]
y = basetable[["target"]]
logreg = linear_model.LogisticRegression()
logreg.fit(X, y)
# Assign the coefficients to a list coef
coef = ____.____
for p,c in zip(predictors,list(coef[0])):
print(p + '\t' + str(c))
# Assign the intercept to the variable intercept
intercept = ____.____
print(intercept)