---
title: Monotonic constraints
description: How to force an XGBoost model to learn only monotonic (always increasing or always decreasing) relationships between chosen features and the target.

---

# Monotonic constraints {: #monotonic-constraints }

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 <em>monotonic constraints</em>, 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&mdash;increasing or decreasing&mdash; by creating feature lists and applying them in [**Advanced options > Feature Constraints**](feature-con). You can also create lists and retrain models, from the Leaderboard menu, after the initial model run.

## General workflow {: #general-workflow }


Typically, working with monotonic constraints follows the workflow described below. Review the [modeling considerations](#feature-considerations) before starting, including special considerations for time series projects.

1. [Create feature lists](#create-feature-lists) for monotonically increasing and/or monotonically decreasing constraints.

2. Set the target and the modeling feature list.

3. From the **Advanced options** link, [configure feature constraints](feature-con).

4. Start the model build using any of the [modeling modes](model-data#set-the-modeling-mode).

5. When model building finishes, [investigate the results](#evaluate-results).

6. Optionally, [retrain model(s)](#retrain-models-with-new-constraints) using different monotonic constraints (or without constraints).

7. Compare training results between models using the [**Feature Effects**](feature-effects) partial dependence graph to help with final model selection.

## Create feature lists {: #create-feature-lists }

The first step in monotonic modeling is to [create feature lists](feature-lists#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.

## Evaluate results {: #evaluate-results }

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 ![](images/icon-mono.png) badge). To determine if a model was built with constraints, check the Leaderboard model description.

![](images/mono-4.png)

Expand a constrained model and, from the **Describe > Constraints** tab, review the features that were constrained:

![](images/mono-5.png)

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.

![](images/mono-7.png)


Next, calculate and view the [**Feature Effects**](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&mdash;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:

![](images/mono-2.png)

When monotonically decreasing constraints are applied, partial dependence looks more like this:

![](images/mono-3.png)


## Retrain models with new constraints {: #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:

1. 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.

2. Expand the menu and select **Run Selected Model(s) with Constraints**. Note that this option is only available if all selected models support constraints.

3. In the upper part of the screen, the window expands and provides a dropdown for selecting monotonic increasing and decreasing feature lists.

	![](images/mono-6.png)

4. Once set, click **Run Models**.

## Feature considerations {: #feature-considerations}

The following considerations apply to monotonic modeling.

* Blenders that contain monotonic models do not display the MONO label on the Leaderboard.

* Monotonic modeling is available in binary classification and regression projects.

* Monotonic constraints can only be applied between Numeric, Percentage, Length, or Currency type variables and the target.

* Generalized Additive Models, Frequency/Severity, and Frequency/Cost models don't support interactions with features trained with monotonic constraints.

* Only Extreme Gradient Boosted Trees, Generalized Additive Models and Frequency/Severity (both frequency and severity model based on XGBoost) and Frequency/Cost model (both frequency and cost model based on XGBoost) support training with monotonic constraints.

* Extreme Gradient Boosted Trees that include `Search for differences` tasks (i.e., DIFF3), `Search for ratio` tasks (i.e., RATIO3) don’t support training with monotonic constraints. (This is because these tasks tend to change the monotonic correlation between features and predicted target.)

* Constraints for models used by Autopilot or from the Repository can only be set in [advanced options](feature-con#monotonicity) and can't be changed after a project is created.

* New constraints can only be set for models on the Leaderboard.

* If `Include only monotonic models` is selected in advanced options, Autopilot only runs the average blender.

* When using monotonic constraints with time series projects:

	* Only XGB models are supported
	* Prior to the feature derivation process (i.e., monotonic lists added before EDA2), features used for monotonicity will be set as "do not derive."
	* When there is an offset in the blueprint, for example naive predictions, the predictions themselves may not be monotonic after offset is applied. (XGBoost _does_ honor monotonicity.)
	* If the model is a collection of models (per-series XGBoost or Performance Clustered blueprint, for example) monotonicity is preserved per-series/cluster.