# LogScaler

**Compatibility:** `numerical` data

The `LogScaler` performs a statistical transformation on numerical data. It computes the logarithm to convert the scale and shape of the data. You can optionally choose the 0-value for the log transformation and invert it. This effectively enforces a singular boundary on the data (minimum or maximum value).

<figure><img src="https://2225246359-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVGX92M819eIp0rMg5elc%2Fuploads%2FYWczh2rcfLox3m2Lp0hY%2Frdt_transformers-glossary-numerical-logscaler_June%2003%202025.png?alt=media&#x26;token=4bd4d672-992b-4d8c-89a9-349f4a761d21" alt=""><figcaption></figcaption></figure>

```python
from rdt.transformers.numerical import LogScaler

transformer = LogScaler(constant=10.0, invert=False)
```

## Parameters

**`missing_value_replacement`**: Add this argument to replace missing values during the transform phase

<table data-header-hidden><thead><tr><th width="212"></th><th></th></tr></thead><tbody><tr><td>(default) <code>'mean'</code></td><td>Replace all missing values with the average value.</td></tr><tr><td><code>'random'</code></td><td>Replace missing values with a random value. The value is chosen uniformly at random from the min/max range.</td></tr><tr><td><code>'mode'</code></td><td>Replace all missing values with the most frequently occurring value</td></tr><tr><td><code>&#x3C;number></code></td><td>Replace all missing values with the specified number (<code>0</code>, <code>-1</code>, <code>0.5</code>, etc.)</td></tr><tr><td><code>None</code></td><td>Do not replace missing values. The transformed data will continue to have missing values.</td></tr></tbody></table>

**`missing_value_generation`**: Add this argument to determine how to recreate missing values during the reverse transform phase

<table data-header-hidden><thead><tr><th width="203"></th><th></th></tr></thead><tbody><tr><td>(default) <code>'random'</code></td><td>Randomly assign missing values in roughly the same proportion as the original data.</td></tr><tr><td><code>'from_column'</code></td><td>Create a new column to store whether the value should be missing. Use it to recreate missing values. <em>Note: Adding extra columns uses more memory and increases the RDT processing time.</em></td></tr><tr><td><code>None</code></td><td>Do not recreate missing values.</td></tr></tbody></table>

**`constant`**: The constant to set as the 0-value for the log-based transform.&#x20;

<table data-header-hidden><thead><tr><th width="262.5"></th><th></th></tr></thead><tbody><tr><td>(default) <code>0</code></td><td>Do not modify the 0-value of the data</td></tr><tr><td><code>&#x3C;float></code></td><td>A floating point value that acts as the 0-value offset for your data. The log of anything less than this value is undefined so this effectively acts as a boundary for your data.</td></tr></tbody></table>

**`invert`**: Whether to invert the data (about the constant) when performing the log-based transform

<table data-header-hidden><thead><tr><th width="270.5"></th><th></th></tr></thead><tbody><tr><td>(default) <code>False</code></td><td>Do not invert any values. This means that the constant value will effectively be the minimum value for your data. The log transform is only valid for anything that is greater than the constant.</td></tr><tr><td><code>True</code></td><td>Invert the values. This means that the constant value will effectively be the maximum value for your data. The log transform is only valid for anything that is less than the constant.</td></tr></tbody></table>

**`learn_rounding_scheme`**: Add this argument to allow the transformer to learn about rounded values in your dataset.

<table data-header-hidden><thead><tr><th width="249.5"></th><th></th></tr></thead><tbody><tr><td>(default) <code>False</code></td><td>Do not learn or enforce any rounding scheme. When reverse transforming the data, there may be many decimal places present.</td></tr><tr><td><code>True</code></td><td>Learn the rounding rules from the input data. When reverse transforming the data, round the number of digits to match the original.</td></tr></tbody></table>

## FAQ

<details>

<summary>How do I enforce min/max values  with this transformer?</summary>

This transformer enforces a strict minimum or maximum boundary on your data using the `constant` and `invert` parameters. Use the `constant` parameter to sent the boundary and the `invert` parameter to determine whether it's the min (`False`) or max (`True`).&#x20;

If you'd like the minimum or maximum value to be allowed, we suggest setting the boundary to something slightly outside the range that you need.

```python
from rdt.transformers.numerical import LogScaler

transformer = LogScaler(
  constant=10.0 - 1e-10, # allow a value of exactly 10
  invert=False)
```

If you'd like to enforce both a minimum and a maximum value, please use the [LogitScaler](https://docs.sdv.dev/rdt/transformers-glossary/numerical/logitscaler) instead.

</details>
