以 Python 進行信用風險建模
Michael Crabtree
Data Scientist, Ford Motor Company
0.86。loan_status:1 表違約,0 表未違約。0.86。loan_status:1 表違約,0 表未違約。| 違約機率 | 解讀 | 預測 loan status |
|---|---|---|
| 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)。| 子集合 | 用途 | 比例 |
|---|---|---|
| Train | 從資料學習以產生預測 | 60% |
| Test | 用未見過的新資料測試學習成效 | 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 進行信用風險建模