> ## Documentation Index
> Fetch the complete documentation index at: https://docs.openlayer.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Class imbalance ratio

> Learn how to use the class imbalance ratio test

## Definition

The class imbalance ratio test allows you to set a threshold on the ratio between the number of rows from the most common class and the least common class.

## Taxonomy

* **Task types**: Tabular classification, text classification.
* **Availability**: <Tooltip tip="Continuously evaluate your models and datasets as you iterate on their versions.">development</Tooltip>.

## Why it matters

* Class imbalance can significantly impact the performance of predictive models.
* Measuring the class imbalance ratio helps select more appropriate [evaluation metrics](/tests/performance/aggregate-metrics#available-metrics).
* Awareness of the extent of class imbalance guides the choice of model and data preprocessing techniques.
* While class imbalance is inherent to certain problems, it is important to continuously measure the class imbalance ratio to ensure that it does not go out of control.

## Test configuration examples

If you are writing a `tests.json`, here are a few valid configurations for the character length test:

<CodeGroup>
  ```json Development theme={null}
  [
    {
      "name": "Class imbalance ratio greater than 0.1",
      "description": "Asserts that the ratio between majority and minotiry classes is greater than 0.1",
      "type": "integrity",
      "subtype": "classImbalanceRatio",
      "thresholds": [
        {
          "insightName": "classImbalance",
          "insightParameters": null,
          "measurement": "classImbalanceRatio",
          "operator": ">",
          "value": 0.1
        }
      ],
      "subpopulationFilters": null,
      "mode": "development",
      "usesValidationDataset": true, // Apply test to the validation set
      "usesTrainingDataset": false,
      "usesMlModel": false,
      "syncId": "b4dee7dc-4f15-48ca-a282-63e2c04e0689" // Some unique id
    }
  ]
  ```

  ```json Monitoring theme={null}
  [
    {
      "name": "Class imbalance ratio greater than 0.1",
      "description": "Asserts that the ratio between majority and minotiry classes is greater than 0.1",
      "type": "integrity",
      "subtype": "classImbalanceRatio",
      "thresholds": [
        {
          "insightName": "classImbalance",
          "insightParameters": null,
          "measurement": "classImbalanceRatio",
          "operator": ">",
          "value": 0.1
        }
      ],
      "subpopulationFilters": null,
      "mode": "monitoring",
      "usesProductionData": true,
      "evaluationWindow": 3600, // 1 hour
      "delayWindow": 0,
      "syncId": "b4dee7dc-4f15-48ca-a282-63e2c04e0689" // Some unique id
    }
  ]
  ```
</CodeGroup>

## Related

* Dealing with class imbalance, [part 1](https://www.openlayer.com/blog/post/dealing-with-class-imbalance-part-1) and [part 2](https://www.openlayer.com/blog/post/dealing-with-class-imbalance-part-2).
