異なる変数セットを使ってみる
ロジスティック回帰モデルに変数を追加して複雑さを増しても、必ずしも精度が上がるとは限りません。この演習では、モデルに3つの変数を追加すると精度が向上するかどうかを確かめます。
variables_1 と variables_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))