# Feature Constraints
URL: https://docs.datarobot.com/en/docs/classic-ui/modeling/build-models/adv-opt/feature-con.html

> Describes the settings available from the Feature Constraints advanced option tab, where you can control the influence, both up and down, between variables and the target.

# Feature Constraints

The Feature Constraints tab provides the tools described in the table below for applying constraints. Once you have completed the desired fields and built models, use the [Describe > Constraints](https://docs.datarobot.com/en/docs/classic-ui/modeling/analyze-models/describe/monotonic.html) Leaderboard tab to evaluate results of models trained with constraints.

| Constraint | Description |
| --- | --- |
| Monotonicity | Controls the influence, both up and down, between variables and the target. |
| Aggregate target class | Configures how classes are aggregated for multiclass modeling. |
| Trim target labels | Configures how labels are trimmed for multilabel modeling. |
| Pairwise Interactions | Controls which pairwise interactions are included in Generalized Additive Model (GA2M) output. (Not available for unsupervised or time series projects.) |

## Monotonicity

[Monotonicity](https://docs.datarobot.com/en/docs/classic-ui/modeling/analyze-models/describe/monotonic.html) forces a directional relationship between features and the target. Use this tab to apply monotonic [feature lists](https://docs.datarobot.com/en/docs/classic-ui/modeling/analyze-models/describe/monotonic.html#create-feature-lists), choose models, and make a positive class assignment.

### Monotonic Increasing / Decreasing

Monotonic Increasing and Monotonic Decreasing set the feature lists you want DataRobot to apply to ensure monotonic modeling. From the dropdowns, select a list to use to enforce monotonically increasing and/or decreasing constraints. Remember that these apply on top of the selected model building feature list.

Note that this option is only available if the project has a numeric-only feature list defined. You can [create an appropriate feature list](https://docs.datarobot.com/en/docs/classic-ui/modeling/build-models/build-basic/feature-lists.html#create-feature-lists-from-the-data-page) prior to modeling. You can also create feature lists and retrain models, from the Leaderboard menu, after the initial model run.

The following options are available:

| Feature list | Description |
| --- | --- |
| No Constraints | When this option is selected, DataRobot applies no monotonic constraints during training. |
| Raw Features | This option is only available when all features in the Raw Features list are of the type numeric, percentage, length, and/or currency. |
| Informative Features | This option is only available when all features in the Informative Features list are of the type numeric, percentage, length, and/or currency. |
| User-defined feature list(s) | All lists that you defined for the project that meet the variable type requirement. |

### Include only monotonic models

When selected, DataRobot will only build (via Autopilot) or make available via the Repository those models that support monotonic constraints. Additionally, Autopilot only creates the [AVG Blender](https://docs.datarobot.com/en/docs/reference/pred-ai-ref/leaderboard-ref.html#blender-models).

### Positive Class Assignment

The Positive Class Assignment option is available for binary classification projects only. It sets the class to use when a prediction scores higher than the classification threshold. When applying monotonic constraints, DataRobot applies the constraint between the value of the predictor and the probability of positive class.

By default, DataRobot sorts alphanumerically and then assigns the second value as the positive class. For example, if you load a dataset with a target of { `1`, `0`} or { `Yes`, `No`}, or { `True`, `False`}, the positive class in each case, after alphanumeric sorting, is `1`, `Yes`, and `True`, respectively.

## Aggregate / trim

You can configure how DataRobot manages support for projects with many classes or labels. Use the appropriate toggle, which will appear depending on your project type:

- Aggregate target classesmanages classes formulticlassprojects.
- Trim target labelsmanages labels formultilabelprojects.

### Aggregate target classes

To configure aggregation settings, scroll to Aggregate target classes.

The following table describes each field:

|  | Element | Description |
| --- | --- | --- |
| (1) | Aggregate target classes | Enables the aggregation functionality. When more than 1,000 classes are detected, the selection is on and cannot be changed. If fewer than 1,000 classes, the selection is off by default but can be enabled. |
| (2) | Name of aggregation class | Sets the name of the "other" bin—the bin containing all classes that do not fall within the configuration set for this aggregation plan. It represents all the rows for the excluded values in the dataset. The provided name must differ from all existing target values in the column. |
| (3) | Min frequency for non-aggregate classes | Sets the minimum occurrence of rows belonging to a class that is required to avoid being bucketed in the "other" bin. That is, classes with fewer instances will be collapsed into a class. |
| (4) | Max number of non-aggregate classes | Sets the final number of classes after aggregation. The last class being the "other" bin. (For example, if you enter 900, there will be 899 class bins from your data and 1 "other" bin of aggregated classes.) Enter a value between 3-1,000. |
| (5) | Classes to be excluded from aggregation | Identifies a comma-separated list of classes that will be preserved from aggregation, ensuring the ability to predict on less frequent classes that are of interest. |

#### Aggregation example

A dataset has the following parameters of the target column, with 8 unique values (classes).

| Class | Row count |
| --- | --- |
| A | 1024 |
| B | 512 |
| C | 256 |
| D | 128 |
| E | 64 |
| F | 32 |
| G | 16 |
| H | 8 |

The parameters are set as follows:

| Parameter | Value |
| --- | --- |
| Name of aggregation class | DR_RARE_TARGET_VALUES |
| Min frequency for non-aggregate classes | 50 |
| Max number of non-aggregate classes | 5 |
| Classes to be excluded from aggregation | [E, H] |

Class mapping initially applies the minimum frequency requirement, as follows:

| Class | Row count | Impact |
| --- | --- | --- |
| A | 1024 | None, above minimum frequency |
| B | 512 | None, above minimum frequency |
| C | 256 | None, above minimum frequency |
| D | 128 | None, above minimum frequency |
| E | 64 | None, above minimum frequency |
| Other bin | 48 | Combined rows of F and G above; did not meet minimum frequency |
| H | 8 | Excluded from aggregation |

So far, the class mapping has resulted in 7 unique values (F and G dropped and replaced with an aggregated class). The "Max number of classes" parameter sets the maximum to five, requiring two more "drops." DataRobot will next drop the least frequent that are not excluded from aggregation (E and H are excluded) and so drops C and D. As a result, the final target class values distribution will be:

- Classes A and B are most frequent.
- Classes E and H are excluded from aggregation.
- Classes C, D, F, and G are aggregated into a single class, DR_RARE_TARGET_VALUES.

The final five classes for modeling are:

| Class | Row count |
| --- | --- |
| A | 1024 |
| B | 512 |
| Aggregated classes (C, D, Other) | 256 + 128 + 48 |
| E | 64 |
| H | 8 |

### Trim target labels

To configure the labels used for multilabel modeling, scroll to Trim target labels.

The following table describes each field:

|  | Element | Description |
| --- | --- | --- |
| (1) | Trim target labels | Enables the trimming functionality. When more than 1,000 labels are detected, the selection is on and cannot be changed. If fewer than 1,000 labels, the selection is off by default but can be enabled. |
| (2) | Frequency minimum | Sets the minimum occurrence of rows containing this label that is required to avoid being removed. That is, labels with fewer instances will be trimmed (unless specified as a protected label). |
| (3) | Maximum labels | Sets the final number of labels after trimming. Enter a value between 2-1,000. |
| (4) | Protected labels | Identifies a comma-separated list of labels that will be preserved from trimming, regardless of frequency. This ensures the ability to predict on less frequent labels that are of interest. |

## Pairwise Interactions

Use this setting to control which interactions are permitted to interact during the training of a [GA2M](https://docs.datarobot.com/en/docs/reference/pred-ai-ref/ga2m.html) model. The setting is often applied in cases where there are certain features that are not permitted to interact due to regulatory constraints.

> [!NOTE] Note
> Specified pairwise interactions are not guaranteed to appear in a model's output. Only the interactions that add signal to a model according to the algorithm will be featured in the output. For example, if you specify an interaction group of features A, B, and C, then AxB, BxC, and AxC are the interactions considered during model training. If only AxB adds signal to the model, then only AxB is included in the model's output (excluding BxC and AxC).

You must provide a CSV file that specifies the pairwise interactions you want to include. Click the File Requirements link for more information about the limitations and format needed for the CSV. The pop-up modal includes an example showing how to structure your CSV in a case that specifies two allowed pairwise interaction groups.

Apply the required formatting and limitations to the CSV, and then click Browse to upload it (or drag and drop). DataRobot begins validating the CSV to ensure it matches the file requirements, and indicates any formatting errors with a message:

After successful CSV upload, you can begin training GA2M models. When the models are built, examine their output in the [Rating Tables](https://docs.datarobot.com/en/docs/classic-ui/modeling/analyze-models/describe/rating-table-classic.html) tab. The output indicates the pairwise interactions that you specified.

---
