逻辑回归基础
您已经清洗了数据,并创建了新的数据集 cr_loan_clean。
回想一下第 1 章中的最后一幅散点图:当 loan_int_rate 较高时,违约更多。利率好理解,但它对于预测违约概率到底有多大用处呢?
由于您还没有尝试预测违约概率,请先只用 loan_int_rate 试着创建并训练一个逻辑回归模型。还要查看模型的内部参数(相当于设置),以了解仅用这一列时模型的结构。
数据集 cr_loan_clean 已加载到工作区。
本练习是课程的一部分
Python 信用风险建模
练习说明
- 使用
loan_int_rate和loan_status列创建X和y集合。 - 创建并在训练数据上拟合一个逻辑回归模型,命名为
clf_logistic_single。 - 使用
.get_params()打印模型的参数。 - 使用
.intercept_属性查看模型的截距。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Create the X and y data sets
X = ____[[____]]
y = ____[[____]]
# Create and fit a logistic regression model
____ = ____()
clf_logistic_single.____(X, np.ravel(____))
# Print the parameters of the model
print(____.____())
# Print the intercept of the model
print(____.____)