擬合邏輯斯模型
大學正在研究「讀書時數」與「特定測驗成績」之間的關係,並提供了一個資料集,包含學生的讀書時數,以及他們是否通過測驗,並請你擬合模型來預測未來表現。
資料已放在變數 hours_of_study 與 outcomes 中。請使用這些資料來擬合一個 LogisticRegression 模型。為方便起見,numpy 已以 np 匯入。
本練習屬於課程
Python 機率基礎
練習說明
- 從
sklearn.linear_model匯入LogisticRegression。 - 使用
LogisticRegression(C=1e9)建立模型。 - 將資料傳入
model.fit()方法。 - 為每個參數建立變數,從模型指派其數值,並印出參數
beta1與beta0。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Import LogisticRegression
from sklearn.linear_model import ____
# sklearn logistic model
model = ____(C=1e9)
model.____(____, ____)
# Get parameters
beta1 = model.coef_[0][0]
beta0 = model.intercept_[0]
# Print parameters
print(____, ____)