---
title: Bias and Fairness
description: Describes the Bias and Fairness advanced option tab, where you can set protected features, choose a fairness metric, and configure bias mitigation techniques.

---

# Bias and Fairness {: #bias-and-fairness }

Bias and Fairness testing provides methods to calculate fairness for a binary classification model and attempt to identify any biases in the model's predictive behavior. In DataRobot, bias represents the difference between a model's predictions for different populations (or groups) while fairness is the measure of the model's bias.

Select protected features in the dataset and choose fairness metrics and mitigation techniques either [before model building](#configure-metrics-and-mitigation-pre-autopilot) or [from the Leaderboard](#configure-metrics-and-mitigation-post-autopilot) once models are built. [Bias and Fairness insights](bias/index) help identify bias in a model and visualize the root-cause analysis, explaining why the model is learning bias from the training data and from where.

Bias mitigation in DataRobot is a technique for reducing (“mitigating”) model bias for an identified [protected feature](glossary/index#protected-feature)&mdash;by producing predictions with higher scores on a selected fairness metric for one or more groups (classes) in a protected feature. It is available for binary classification projects, and typically results in a small reduction in accuracy in exchange for greater fairness.

See the [Bias and Fairness](b-and-f/index) resource page for more complete information on the generally available bias and fairness testing and mitigation capabilities.

## Configure metrics and mitigation pre-Autopilot {: #configure-metrics-and-mitigation-pre-autopilot }

Once you select a target, click **Show advanced options** and select the **Bias and Fairness** tab. From the tab you can set [fairness metrics](#set-fairness-metrics) and [mitigation techniques](#set-mitigation-techniques).

![](images/bias-mit-1.png)

### Set fairness metrics {: #set-fairness-metrics }

To configure **Bias and Fairness**, set the values that define your use case. For additional detail, refer to the [bias and fairness reference](bias-ref) for common terms and metric definitions.

![](images/bias-and-fairness-1.png)

1. Identify up to 10 **Protected Features** in the dataset. Protected features must be categorical. The model's fairness is calculated against the protected features selected from the dataset.

	![](images/bias-and-fairness-2.png)

2. Define the **Favorable Target Outcome**, i.e., the outcome perceived as favorable for the protected class relative to the target. In the below example, the target is "salary" so annual salaries are listed under Favorable Target Outcome, and a favorable outcome is earning greater than 50K.

	![](images/bias-and-fairness-3.png)

3. Choose the **Primary Fairness Metric** most appropriate for your use case from the five options below.

	??? tip "Help me choose"
		<a name="select-a-metric"></a>
	    If you are unsure of the best metric for your model, click **Help me choose**.

	    ![](images/bias-and-fairness-10.png)

	    DataRobot presents a questionnaire where each question is determined by your answer to the previous one. Once completed, DataRobot recommends a metric based on your answers.

	    ![](images/bias-and-fairness-5.png)

	    Because bias and fairness are ethically complex, DataRobot's questions cannot capture every detail of each use case. Use the recommended metric as a guidepost; it is not necessarily the correct (or only) metric appropriate for your use case. Select different metrics to observe how answering the questions differently would affect the recommendation.

	    Click **Select** to add the highlighted option to the **Primary Fairness Metric** field.


	| Metric  |  Description  |
	|---------|---------------|
	| [Proportional Parity](bias-ref#proportional-parity) | For each protected class, what is the probability of receiving favorable predictions from the model?  This metric (also known as "Statistical Parity" or "Demographic Parity") is based on equal representation of the model's target across protected classes.  |
	| [Equal Parity](bias-ref#equal-parity)  | For each protected class, what is the total number of records with favorable predictions from the model?  This metric is based on equal representation of the model's target across protected classes. |
	| Prediction Balance ([Favorable Class Balance](bias-ref#favorable-class-balance) and [Unfavorable Class Balance](bias-ref#unfavorable-class-balance))  | For all actuals that were favorable/unfavorable outcomes, what is the average predicted probability  for each protected class? This metric is based on equal representation of the model's average raw scores across each protected class and is part of the set of Prediction Balance fairness metrics. |
	| [True Favorable Rate Parity](bias-ref#true-favorable-rate-parity) and [True Unfavorable Rate Parity](bias-ref#true-unfavorable-rate-parity)  | For each protected class, what is the probability of the model predicting the  favorable/unfavorable outcome for all actuals of the favorable/unfavorable outcome? This metric is based on equal error. |
	| [Favorable Predictive Value Parity](bias-ref#favorable-predictive-value-parity) and [Unfavorable Predictive Value Parity](bias-ref#unfavorable-predictive-value-parity) | What is the probability of the model being correct (i.e., the actual results being favorable/unfavorable)?  This metric (also known as "Positive Predictive Value Parity") is based on equal error.  |


	![](images/bias-and-fairness-4.png)

	The fairness metric serves as the foundation for the calculated fairness score; a numerical computation of the model's fairness against the protected class.

4. Set a **Fairness Threshold** for the project. The threshold serves as a benchmark for the model's fairness score. That is, it measures if a model performs within appropriate fairness bounds for each protected class. It does not affect the fairness score or performance of any protected class. (See the [reference section](bias-ref) for more information.)

	![](images/bias-and-fairness-11.png)


### Set mitigation techniques {: #set-mitigation-techniques }

![](images/bias-mit-1a.png)

Select a bias mitigation technique for DataRobot to apply automatically. DataRobot uses the selected technique to automatically attempt bias mitigation for the top three full or Comprehensive Autopilot Leaderboard models (based on accuracy). You can also initiate bias mitigation [manually](#retrain-with-mitigation) after Autopilot completes. (If you used [Quick Autopilot mode](model-ref#quick-autopilot), for example, manual mode allows you to apply mitigation to selected models). With either method, once applied, you can compare [mitigated versus unmitigated models](#compare-models).

??? tip "How does mitigation work?"
	Specifically, mitigation copies an affected blueprint and then adds either a pre- or post-processing task, depending on the **Mitigation technique** selected.

	![](images/bias-mit-11.png)


The table below summarizes the fields:

Field | Description
----- | -----------
Bias mitigation feature | Lists the protected feature(s); select one from which to reduce the model's bias towards.
Include as a predictor variable | Sets whether to include the mitigation feature as an input to model training.
Bias mitigation technique | Sets the mitigation technique and the point in model processing when mitigation is applied.

The steps below provide greater detail for each field:

1. Select a feature from the **Bias mitigation feature** dropdown, which lists the feature(s) that you set as protected in the **Protected features** field for general Bias and Fairness settings. This is the feature you would like to reduce the model’s bias towards.

	![](images/bias-mit-2.png)

2. Once the mitigation feature is set, DataRobot computes data quality for the feature. When the check is successful, the option to include the protected feature as a predictor variable becomes available. Check the box to use the feature to attempt mitigation and to include the mitigation feature as an input into model training. Leave it unchecked to use the feature for mitigation only, not as a training input. This can be useful when you are legally prohibited from, or don't want to, include sensitive data as a model input but you would like to attempt mitigation based on it.

	??? tip "What does the data quality check identify?"
	    During the data quality check, there are three basic questions answered for the chosen mitigation feature and the chosen target:

	    1. Does the mitigation feature have too many rows where the value is completely missing?
	    2. Are there any values of the mitigation feature that are too rare to allow drawing firm conclusions? For example, consider a dataset with 10,000 rows where the mitigated feature is `race`. One of the values, `Inuit`, occurs only seven times, making the sample too small to be representative.
	    3. Are there any combinations of class plus target that are rare or absent? For example, consider a mitigation feature of `gender`. The categories `Male` and `Female` are both numerous, but the positive target label never occurs in `Female` rows.

	    If the quality check does not pass, a warning appears. Address the issues in the dataset, then re-upload and try again.

3. Set the **Mitigation technique**, either:

	* _Preprocessing Reweighing:_ Assigns row-level weights and uses those as a special model input during training to attempt to make the predictions more fair.
	* _Postprocessing with Rejection Option-based Classification (ROBC):_ Changes the predicted label for rows that are close to the prediction threshold (model predictions with the highest uncertainty). Read more about ROBC [here](https://towardsdatascience.com/reducing-ai-bias-with-rejection-option-based-classification-54fefdb53c2e){ target=_blank }. For more details on the applied algorithms, open the model documentation by clicking on the mitigation method task in the model blueprint.

	??? tip "Which fairness metrics does each mitigation techniques use?"
	    The mitigation technique names, "pre" and "post," refer to the point in the workflow (as illustrated in the blueprint) where the technique is applied. For example, reweighing is called "preprocessing" because it happens before the model is trained. Rejection Option-based Classification is called post-processing because it happens after the model has been trained. The techniques use the following metrics.

        Technique | Metric
	    --------- | ------
	    Preprocessing Reweighing | Primarily [Proportional Parity](bias-ref#proportional-parity) (but may, tangentially, improve other fairness metrics).
	    Postprocessing with Rejection Option-based Classification | Proportional Parity and [True Favorable](bias-ref#true-favorable-rate-parity) and [True Unfavorable](bias-ref#true-unfavorable-rate-parity) Rate Parity

4. Start the model building process. DataRobot automatically attempts mitigation on the top three _eligible_ models produced by Autopilot against the **Bias mitigation feature**. Mitigated models can be identified by the BIAS MITIGATION badge on the Leaderboard. See the explanation of what makes a model [eligible for mitigation](#mitigation-eligibility), as well as a table listing ineligible models.

	![](images/bias-mit-3.png)

5. [Compare](#compare-models) bias and accuracy of mitigated vs. unmitigated models.

## Configure metrics and mitigation post-Autopilot {: #configure-metrics-and-mitigation-post-autopilot }

If you did not configure **Bias and Fairness** prior to model building, you can configure [fairness tests](#retrain-with-fairness-tests) and [mitigation techniques](#retrain-with-mitigation) from the Leaderboard.

### Retrain with fairness tests {: #retrain-with-fairness-tests }

The following describes applying fairness metrics to models after Autopilot completes.

1. Select a model and click **Bias and Fairness > Settings**.

    ![](images/bias-index-1.png)

2. Follow the advanced options instructions on [configuring bias and fairness](#set-fairness-metrics).

3. Click **Save**. DataRobot then configures fairness testing for all models in your project based on these settings.

### Retrain with mitigation {: #retrain-with-mitigation }

After Autopilot has finished, you can apply mitigation to any models that have not already been mitigated. To do so, select [one](#single-model-retraining) or [multiple](#multiple-model-retraining) model(s) from the Leaderboard and retrain them with bias mitigation settings applied.

!!! note
    While you cannot retrain an already mitigated model, even on a different protected feature, you can return to the parent and select a different feature or technique for mitigation.

From the [parent model](#identify-mitigated-models), you can view the **Models with Mitigation Applied** table. This table lists relationships between the parent model and any child models with mitigation applied. Note the parent model does _not_ have mitigation applied (1). All child mitigated models are listed by model ID (2), including their mitigation settings.

![](images/bias-mit-13.png)


#### Single-model retraining {: #single-model-retraining }

!!! note
    If you haven't previously completed the Bias and Fairness configuration in advanced options prior to model building, you must first set those fields via the [**Bias and Fairness > Settings**](#set-fairness-metrics) tab.

To apply mitigation to a single Leaderboard model after Autopilot completes:

1. Expand any [eligible](#mitigation-eligibility) Leaderboard model and open **Bias and Fairness > Bias Mitigation**.

	![](images/bias-mit-10.png)

2. [Configure the fields](#set-mitigation-techniques) for bias mitigation.

3. Click **Apply** to start building a new, mitigated version of the model. When training is complete, the model can be [identified](#identify-mitigated-models) on the Leaderboard by the BIAS MITIGATION badge.

4. [Compare](#compare-models) bias and accuracy of mitigated vs. unmitigated models.


#### Multiple-model retraining {: #multiple-model-retraining }

To apply mitigation to multiple Leaderboard models after Autopilot completes:

1. Use the checkboxes to the left of any [eligible](#mitigation-eligibility) models that have not already been mitigated.

2. From the menu, select **Model processing > Apply bias mitigation for selected models**.

	![](images/bias-mit-4.png)

3. In the resulting window, [configure the fields](#set-mitigation-techniques) for bias mitigation.

	![](images/bias-mit-5.png)

4. Click **Apply** to start building new, mitigated versions of the models. When training is complete, the models can be [identified](#identify-mitigated-models) on the Leaderboard by the BIAS MITIGATION badge.

5. [Compare](#compare-models) bias and accuracy of mitigated vs. unmitigated models.


### Identify mitigated models {: #identify-mitigated-models }

The Leaderboard provides several indicators for mitigated and parent (unmitigated versions) models:

* A BIAS MITIGATION badge. Use the Leaderboard search to easily identify all mitigated  models.

	![](images/bias-mit-6.png)

* Model naming reflects [mitigation settings](#set-mitigation-techniques) (technique, protected feature, and predictor variable status).

	![](images/bias-mit-7.png)


* The **Bias Mitigation** tab includes a link to the original, unmitigated parent model.

	![](images/bias-mit-8.png)

### Compare models {: #compare-models }

Use the [**Bias vs Accuracy**](bias-tab) tab to compare the bias and accuracy of mitigated vs. unmitigated models. The chart will likely show that mitigated models have higher fairness scores (less bias) than their unmitigated version, but with lower accuracy.

![](images/bias-mit-9.png)


Before a model (mitigated or unmitigated) becomes available on the chart, you must first calculate its fairness scores. To compare mitigated or unmitigated:

1. Open a model displaying the BIAS MITIGATION badge and navigate to [**Bias and Fairness > Per-Class Bias**](per-class). The fairness score is calculated automatically once you open the tab.

2. Navigate to the **Bias and Fairness > Bias Mitigation** tab to retrieve a link to the parent model. Click the link to open the parent.

3. From the parent model, visit the **Bias and Fairness > Per-Class Bias** tab to automatically calculate the fairness score.

4. Open the [**Bias vs Accuracy**](bias-tab) tab and compare the results. In this example, you can see that the mitigated model (shown in green) has higher accuracy (Y-axis) and fairness (X-axis) scores than the parent (shown in magenta).

	![](images/bias-mit-12.png)

## Mitigation eligibility {: #mitigation-eligibility }

DataRobot selects the top three _eligible_ models for mitigation, and as a result, those labeled with the BIAS MITIGATION badge may not be the top three models on the Leaderboard after Autopilot runs. Other models may be in a higher position on the Leaderboard but will not have mitigation applied because they were ineligible.

If you select **Preprocessing Reweighing** as the mitigation technique, the following models are ineligible for reweighing because the models don’t use weights:

* Nystroem Kernel SVM Classifier
* Gaussian Process Classifier
* K-nearest Neighbors Classifier
* Naive Bayes Classifier
* Partial Least Squares Classifier
* Legacy Neural Net models: "vanilla" Neural Net Classifier, Dropout Input Neural Net Classifier, "vanilla" Two Layer Neural Net Classifier, Two Hidden Layer Dropout Rectified Linear Neural Net Classifier, (but note that contemporary Keras models can be mitigated)
* Certain basic linear models: Logistic Regression, Regularized Logistic Regression (but note that ElasticNet models can be mitigated)
* Eureqa and Eureqa GAM Classifiers
* Two-stage Logistic Regression
* SVM Classifier, with any kernel


If you select either mitigation technique, the following models and/or projects are ineligible for mitigation:

* Models that have already had bias mitigation applied.
* Majority Class Classifier (predicts a constant value).
* [External Predictions](external-preds) models (uses a special column uploaded with the training data, cannot make new predictions).
* Blender models.
* Projects using [Smart Downsampling](smart-ds).
* Projects using custom weights.
* Projects where the **Mitigation Feature** is missing over 50% of its data.
* Time series or OTV projects (i.e., any project with time-based partitioning).
* Projects run with [SHAP](shap-pe) value support.
* Single-column, standalone text converter models: Auto-Tuned Word N-Gram Text Modeler, Auto-Tuned Char N-Gram Modeler, and Auto-Tuned Summarized Categorical Modeler.




## Bias mitigation considerations {: #bias-mitigation-considerations }

Consider the following when working with bias mitigation:

* Mitigation applies to a single, categorical protected feature.

* For the **ROBC** mitigation technique, the mitigation feature must have at least two classes that each have at least 100 rows in the training data. For the **Preprocessing Reweighing** technique, there is no explicit minimum row count, but mitigation effectiveness may be unpredictable with very small row counts.
