Aan de slagGa gratis aan de slag

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.

Deze oefening maakt deel uit van de cursus

Credit Risk Modeling in Python

Cursus bekijken

Oefeninstructies

  • Create and train a gradient boosted tree using XGBClassifier() and name it clf_gbt.
  • Predict probabilities of default on the test data and store the results in gbt_preds.
  • Create two data frames, preds_df and true_df, to store the first five predictions and true loan_status values.
  • Concatenate and print the data frames true_df and preds_df in order, and check the model's results.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# 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))
Code bewerken en uitvoeren