Python ile Kredi Riski Modellemesi
Michael Crabtree
Data Scientist, Ford Motor Company
XGBoost için optimize edilmiş dahili yapı DMatrix kullanır# 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 için sınıflandırmayı belirtir'eval_metric':'auc', XGBoost'un performansı AUC ile puanlamasını söyler# 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(), eğitime optimize edilmiş, xgboost için özel bir nesne oluştururcross_val_score() ile çapraz doğrulama ve puanlama metriklerini kullanır# 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 ile Kredi Riski Modellemesi