開始使用免費開始

使用不同的變數組合

在你的羅吉斯回歸模型中加入更多變數、增加複雜度,並不會自動帶來更高的準確度。這個練習要讓你驗證:在模型中多加入 3 個變數,是否真的能提升準確度。

variables_1variables_2 已經在你的環境中:你可以把它們印到主控台,看看長什麼樣子。

本練習屬於課程

Python 預測分析入門

檢視課程

練習說明

  • 使用相較於 variables_1 多 3 個變數的 variables_2 來擬合 logreg 模型。
  • 產生此模型的預測。
  • 計算此模型的 AUC。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Create appropriate DataFrames
X_1 = basetable[variables_1]
X_2 = basetable[variables_2]
y = basetable[["target"]]

# Create the logistic regression model
logreg = linear_model.LogisticRegression()

# Make predictions using the first set of variables and assign the AUC to auc_1
logreg.fit(X_1, y)
predictions_1 = logreg.predict_proba(X_1)[:,1]
auc_1 = roc_auc_score(y, predictions_1)

# Make predictions using the second set of variables and assign the AUC to auc_2
logreg.____(____, ____)
predictions_2 = ____.____(____)[____,____]
auc_2 = ____(____, ____)

# Print auc_1 and auc_2
print(round(auc_1,2))
print(round(auc_2,2))
編輯並執行程式碼