使用不同的变量集合
向逻辑回归模型添加更多变量、提高复杂度,并不会自动带来更高的准确度。本练习中,您将检验在模型中新增 3 个变量是否会得到更准确的模型。
variables_1 和 variables_2 已在您的环境中可用:您可以将它们打印到控制台,查看其内容。
本练习是课程的一部分
Python 预测分析入门
练习说明
- 使用
variables_2拟合logreg模型;与variables_1相比,它额外包含 3 个变量。 - 为该模型生成预测。
- 计算该模型的 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))