Course Wiki

XGBoost parameter tuning — Machine Learning Zoomcamp Module 6

XGBoost has various tunable parameters but the three most important ones are:

Machine Learning Zoomcamp › Module 6: Decision Trees and Ensemble Learning › XGBoost parameter tuning

Notes

XGBoost has various tunable parameters but the three most important ones are:

For XGBoost models, there are other ways of finding the best parameters as well but the one we implement in the notebook follows the sequence of:

Other useful parameter are:

Alternative: Tuning XGBoost using a loop

Instead of repeating the training process manually for each eta value, you can use a loop to automate it (and other parameters to be tuned):

# Train XGBoost models for each eta and store AUC results
scores = {} # dictionary to store results for each eta
etas = [0.01, 0.05, 0.1, 0.3, 1.0] # list of parameter values. in this case it is 'eta'.

for eta in etas:
    evals_result = {}

    xgb_params = {
        'eta': eta,
        'max_depth': 6,
        'min_child_weight': 1,

        'objective': 'binary:logistic',
        'eval_metric': 'auc',

        'nthread': 8,
        'seed': 1,
        'verbosity': 1
    }

    model = xgb.train(
        xgb_params,
        dtrain,
        evals=watchlist,
        verbose_eval=0,
        num_boost_round=200,
        evals_result=evals_result
    )

    columns = ['iter', 'train_auc', 'val_auc']
    train_aucs = list(evals_result['train'].values())[0]
    val_aucs = list(evals_result['val'].values())[0]

    df_results = pd.DataFrame(
        list(zip(range(1, len(train_aucs) + 1), train_aucs, val_aucs)),
        columns=columns
    )

    key = f'eta={eta}'
    scores[key] = df_results

Add notes from the video (PRs are welcome)

⚠️ The notes are written by the community.
If you see an error here, please create a PR with a fix.

Key concepts

Sources


DataTalks.Club. Hosted on GitHub Pages. Built with Rustkyll. We use cookies.