Python을 활용한 신용 위험 모델링
Michael Crabtree
Data Scientist, Ford Motor Company
XGBoost에 최적화된 내부 구조인 DMatrix를 사용합니다# Set the number of folds
n_folds = 2
# Set early stopping number
early_stop = 5
# Set any specific parameters for cross validation
params = {'objective': 'binary:logistic',
'seed': 99, 'eval_metric':'auc'}
'binary':'logistic'는 loan_status에 대한 분류를 지정하는 데 사용됩니다'eval_metric':'auc'는 XGBoost가 모델의 성능을 AUC로 평가하도록 지정합니다# Restructure the train data for xgboost
DTrain = xgb.DMatrix(X_train, label = y_train)
# Perform cross validation
xgb.cv(params, DTrain, num_boost_round = 5, nfold=n_folds,
early_stopping_rounds=early_stop)
DMatrix()는 훈련에 최적화된 xgboost용 특수 객체를 생성합니다cross_val_score() 함수로 교차 검증과 평가 지표를 사용합니다# Import the module
from sklearn.model_selection import cross_val_score
# Create a gbt model
xg = xgb.XGBClassifier(learning_rate = 0.4, max_depth = 10)
# Use cross valudation and accuracy scores 5 consecutive times
cross_val_score(gbt, X_train, y_train, cv = 5)
array([0.92748092, 0.92575308, 0.93975392, 0.93378608, 0.93336163])
Python을 활용한 신용 위험 모델링