> 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/categorical/uniformencoder.md).

# UniformEncoder

**Compatibility:** `categorical` or `boolean` data

The `UniformEncoder` transforms data that represents categorical values into a uniform distribution in the `[0,1]` interval. It is highly accurate at preserving the overall frequencies of each category.

<figure><img src="https://2225246359-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVGX92M819eIp0rMg5elc%2Fuploads%2FTBFs3heAY2fY0Q5Yo6v5%2Frdt_transformers-glossary-categorical-uniform-encoder_June%2002%202025.png?alt=media&amp;token=1fc2c7f3-3445-438e-a29c-9bc7e3af0ab6" alt=""><figcaption></figcaption></figure>

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

transformer = UniformEncoder()
```

## Parameters

**`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.</td></tr></tbody></table>

### Examples

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

transformer = UniformEncoder(
    order_by='alphabetical'
)
```

The transformer assigns each category to a unique, non-overlapping subset of the `[0,1]` interval. The length of the interval is based on the category's frequency. For example if category `'CASH'` occurs with 60% frequency, the subset will have the length `0.6` such as `[0.2, 0.8]`.

## 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
{
  'CREDIT': 0.2, 
  'CASH': 0.6,
  'DEBIT': 0.2
}
```

**`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
{
  'CREDIT': [0, 0.2],
  'CASH': [0.2, 0.8],
  'DEBIT': [0.8, 1.0]
}
```

## FAQs

<details>

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

The UniformEncoder is shown to preserve the frequency of each category value with high accuracy. This is especially useful if you have a data imbalance, for example if `True` occurs only 1% of the time while `False` occurs 99% of the time.&#x20;

</details>

<details>

<summary>What if I'd like to sort the values by a custom order?</summary>

If the values in the column represent ordered categories, the column should be marked as *ordinal*, not *categorical*. Please see the transformers available for the [ordinal sdtype](/rdt/transformers-glossary/ordinal.md).

</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/categorical/uniformencoder.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.
