> For the complete documentation index, see [llms.txt](https://docs.sdv.dev/rdt/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.sdv.dev/rdt/transformers-glossary/ordinal/ordereduniformencoder.md).

# OrderedUniformEncoder

**Compatibility:** `ordinal` data

The `OrderedUniformEncoder` transforms data that represents ordered categorical values into a uniform distribution in the `[0,1]` interval. It preserves the frequencies of each category with high accuracy.

<figure><img src="https://2225246359-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVGX92M819eIp0rMg5elc%2Fuploads%2FZXTbdkN7BsWHivuXFGLP%2Frdt_transformers-glossary-categorical-ordered-uniform-encoder_June%2002%202025.png?alt=media&amp;token=87f000f1-4e59-445c-95e0-913645d8cdd6" alt=""><figcaption></figcaption></figure>

```python
from rdt.transformers.categorical import OrderedUniformEncoder

transformer = OrderedUniformEncoder(order=['STRONGLY DISAGREE', 'DISAGREE', 'NEUTRAL',
                                           'AGREE', 'STRONGLY AGREE'])
```

## Parameters

(required) **`order`**: Specify an order to the category values

<table data-header-hidden><thead><tr><th width="220.5"></th><th></th></tr></thead><tbody><tr><td><code>[list &#x3C;value>]</code></td><td>An ordered list of the categories that appear in the real data</td></tr></tbody></table>

**`missing_value_encoding`**: Control how to encode missing values present in the categorical column.

<table data-header-hidden><thead><tr><th width="232.5"></th><th></th></tr></thead><tbody><tr><td>(default) <code>'new_category'</code></td><td>Treat missing values as a new category type, just like any non-missing values. <em>Any type of missing value (None, NaN, etc.) is treated as a single category of "missing".</em></td></tr><tr><td><code>None</code></td><td>Do not encode missing values. In this case, missing values will be kept as-is during the forward and reverse transforms. <em>In this case, it's ok if missing values don't appear in the <code>order</code> parameter; if they do, they will be ignored.</em></td></tr></tbody></table>

### Examples

```python
from rdt.transformers.categorical import OrderedUniformEncoder

transformer = OrderedUniformEncoder(order=['STRONGLY DISAGREE', 'DISAGREE', 'NEUTRAL',
                                           'AGREE', 'STRONGLY AGREE'])
```

The transformer assigns each category to a unique, non-overlapping subset of the `[0,1]` interval. The order of the intervals is based on your custom order. The length of the interval is based on the category's frequency. For example if category `'AGREE'` occurs with 20% frequency, the subset will have the length `0.2` such as `[0.5, 0.7]`.

## Attributes

After fitting the transformer, you can access the learned values through the attributes.

**`frequencies`**: A dictionary that maps each category value to the observed frequency, as a float between 0 and 1

```python
>>> transformer.frequencies
{
  'STRONGLY DISAGREE': 0.1, 
  'DISAGREE': 0.2,
  'NEUTRAL': 0.2,
  'AGREE': 0.2,
  'STRONGLY AGREE': 0.3
}
```

**`intervals`**: A dictionary that maps each category value to an interval between `[0,1]`. This allows you to determine the exact rules used for transforming and reverse transforming.

```python
>>> transformer.intervals
{
  'STRONGLY DISAGREE': [0, 0.1], 
  'DISAGREE': [0.1, 0.3],
  'NEUTRAL': [0.3, 0.5],
  'AGREE': [0.5, 0.7],
  'STRONGLY AGREE': [0.7, 1.0]
}
```

## FAQs

<details>

<summary>When should I use this transformer?</summary>

The OrderedUniformEncoder is shown to preserve the frequency of each category value with high accuracy. This is especially useful if you have a data imbalance.

</details>

<details>

<summary>What if my categorical column does not have an order?</summary>

This transformer is only defined for ordinal categorical data. If there is no order, your data is *nominal*. Use the [**UniformEncoder**](/rdt/transformers-glossary/categorical/uniformencoder.md) instead.

</details>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.sdv.dev/rdt/transformers-glossary/ordinal/ordereduniformencoder.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
