Python 信用风险建模
Michael Crabtree
Data Scientist, Ford Motor Company
0.86loan_status 为 1 表示违约,0 表示未违约0.86loan_status 为 1 表示违约,0 表示未违约| 违约概率 | 解释 | 预测贷款状态 |
|---|---|---|
| 0.4 | 不太可能违约 | 0 |
| 0.90 | 很可能违约 | 1 |
| 0.1 | 极不可能违约 | 0 |
0 到 1 之间from sklearn.linear_model import LogisticRegression
clf_logistic = LogisticRegression(solver='lbfgs')
.fit() 方法训练clf_logistic.fit(training_columns, np.ravel(training_labels))
loan_status 外的所有列loan_status(0,1)| 数据子集 | 用途 | 比例 |
|---|---|---|
| 训练集 | 从数据学习以生成预测 | 60% |
| 测试集 | 在未见过的新数据上检验学习效果 | 40% |
X = cr_loan.drop('loan_status', axis = 1)
y = cr_loan[['loan_status']]
train_test_split() 函数X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=.4, random_state=123)
test_size:测试集所占比例random_state:随机种子,确保可复现Python 信用风险建模