Trees for defaults
You will now train a gradient boosted tree model on the credit data, and see a sample of some of the predictions. Do you remember when you first looked at the predictions of the logistic regression model? They didn't look good. Do you think this model be different?
The credit data cr_loan_prep, the training sets X_train and y_train, and the test data X_test is available in the workspace. The XGBoost package is loaded as xgb.
Diese Übung ist Teil des Kurses
Credit Risk Modeling in Python
Anleitung zur Übung
- Create and train a gradient boosted tree using
XGBClassifier()and name itclf_gbt. - Predict probabilities of default on the test data and store the results in
gbt_preds. - Create two data frames,
preds_dfandtrue_df, to store the first five predictions and trueloan_statusvalues. - Concatenate and print the data frames
true_dfandpreds_dfin order, and check the model's results.
Interaktive Übung
Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.
# Train a model
import xgboost as xgb
____ = xgb.____().fit(____, np.ravel(____))
# Predict with a model
____ = clf_gbt.____(____)
# 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.____([____.reset_index(drop = True), ____], axis = 1))