建立 logistic regression 模型
在這個練習中,你將使用 diabetes_df 資料集中的所有特徵,建立一個邏輯斯回歸(logistic regression)模型。這個模型將用來預測測試集中每位個體被診斷為糖尿病的機率。
diabetes_df 資料集已經分割為 X_train、X_test、y_train 和 y_test,並為你預先載入。
本練習屬於課程
使用 scikit-learn 進行監督式學習
練習說明
- 匯入
LogisticRegression。 - 具現化一個邏輯斯回歸模型
logreg。 - 將模型擬合至訓練資料。
- 預測測試集中每位個體被診斷為糖尿病的機率,並將正類機率的陣列存為
y_pred_probs。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Import LogisticRegression
____
# Instantiate the model
logreg = ____
# Fit the model
____
# Predict probabilities
y_pred_probs = logreg.____(____)[____, ____]
print(y_pred_probs[:10])