In some projects (typically insurance and banking), you may want to force the directional relationship between a feature and the target (for example, higher home values should always lead to higher home insurance rates). By training with monotonic constraints, you force certain XGBoost models to learn only monotonic (always increasing or always decreasing) relationships between specific features and the target. For example, increasing values in feature(s) that describe the value of the home have an always increasing relationship with the target,
claim losses. You set the direction of the relationships—increasing or decreasing— by creating feature lists and applying them in Advanced options > Feature Constraints. You can also create lists and retrain models, from the Leaderboard menu, after the initial model run.
Typically, working with monotonic constraints follows the workflow described below.
Create feature lists for monotonically increasing and/or monotonically decreasing constraints.
Set the target and the modeling feature list.
From the Advanced options link, configure feature constraints.
Start the model build using any of the modeling modes.
When model building finishes, investigate the results.
Optionally, retrain model(s) using different monotonic constraints (or without constraints).
Compare training results between models using the Feature Effects partial dependence graph to help with final model selection.
Create feature lists¶
The first step in monotonic modeling is to create feature lists that identify monotonically constrained features. The feature(s) contained in these list(s) are those that have a forced directional relationship, increasing or decreasing, with the target. Note that use of monotonic feature lists does not replace the standard model building feature list. Instead, these lists identify features in the selected model building feature list that should be handled differently.
When creating lists, remember:
- Features must be of type numeric, percentage, length, or currency.
- There can be no feature overlap in the feature lists for monotonically increasing and monotonically decreasing constraints.
- After creating lists, be sure to change the Feature List dropdown to the list for the project model build (otherwise, it remains on the last created list).
- The target feature is automatically added to every feature list.
When model building is complete, there are several tools for investigating and evaluating the results. First, check the Leaderboard to identify the model(s) that are, or can be, trained with monotonic constraints (identified with the MONO badge). To determine if a model was built with constraints, check the Leaderboard model description.
Expand a constrained model and, from the Describe > Constraints tab, review the features that were constrained:
There are cases where some, or all, of the features identified in the constraint list were not used in the final modeling feature list. This happens, for example, when DataRobot creates a reduced feature list for the recommended model. In essence, this also serves as a constraint.
Next, calculate and view the Feature Effects partial dependence graph, checking the results for monotonically constrained features. This graph helps determine whether a monotonically constrained feature maintains the monotonic relationship with the predicted target. Partial dependence is calculated, based on the validation set, between each predictor and predicted target values—it calculates the relationship between average target values and predictor values of each bin. Since impacts from other predictors on predicted target values tend to be averaged out, partial dependence reflects the relationship between an individual predictor and the target. If a model is trained with monotonic constraints, the relationship between monotonically constrained features and predicted target tends to be monotonic.
For example, this graph plots partial dependence on a model trained without constraints:
When monotonically decreasing constraints are applied, partial dependence looks more like this:
Retrain models with new constraints¶
You may decide, after a model build, to change the monotonic feature list and rerun one or more models. To do this:
From the Leaderboard, select models that support constraints by checking the box to the left of the model name. Click the MONO badge to filter the Leaderboard display so that it shows only eligible models.
Expand the menu and select Run Selected Model(s) with Constraints. Note that this option is only available if all selected models support constraints.
In the upper part of the screen, the window expands and provides a dropdown for selecting monotonic increasing and decreasing feature lists.
Once set, click Run Models.