부도 확률 예측하기
모든 데이터 전처리가 완료되었으니 이제 부도 확률을 예측해 보겠습니다. 데이터를 사용해 LogisticRegression() 모델을 학습하고, 이 모델이 부도 확률을 어떻게 예측하는지 살펴보세요.
predict_proba가 생성하는 값을 더 잘 이해하려면, 예측된 부도 확률과 함께 예시 레코드를 나란히 확인해 보는 것이 좋습니다. 처음 다섯 개 예측은 실제 loan_status 값과 비교해 보면 어떻게 보이나요?
데이터 세트 cr_loan_prep과 X_train, X_test, y_train, y_test는 이미 워크스페이스에 로드되어 있습니다.
이 연습은 강의의 일부입니다
Python으로 배우는 신용 리스크 모델링
연습 안내
- 학습 데이터로 로지스틱 회귀 모델을 학습하고
clf_logistic에 저장하세요. - 테스트 데이터에
predict_proba()를 사용해 예측값을 만들고preds에 저장하세요. - 처음 다섯 개 예측과 실제
loan_status값을 저장할 데이터 프레임preds_df와true_df를 만드세요. .concat()을 사용해true_df와preds_df를 한 셋으로 출력하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Train the logistic regression model on the training data
____ = ____(solver='lbfgs').____(____, np.ravel(____))
# Create predictions of probability for loan status using test data
____ = clf_logistic.____(____)
# Create dataframes of first five predictions, and first five true labels
____ = pd.DataFrame(____[:,1][0:5], columns = ['prob_default'])
____ = y_test.____()
# Concatenate and print the two data frames for comparison
print(pd.____([true_df.reset_index(drop = True), preds_df], axis = 1))