> For the complete documentation index, see [llms.txt](https://docs.sov.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.sov.ai/api-reference/extensions/dimensionality-reduction.md).

# Dimensionality Reduction

**Module:** `sovai.extensions.dimensionality_reduction`

## Functions

### `fillna_df()`

```python
def fillna_df(df, verbose = False)
```

Preprocess the panel data.

**Parameters**

| Parameter | Type | Description      |
| --------- | ---- | ---------------- |
| `df`      | —    | —                |
| `verbose` | —    | Default: `False` |

***

### `check_and_scale_data()`

```python
def check_and_scale_data(df)
```

Check if data is scaled in any fashion, and scale it only if it's not scaled.

**Parameters**

| Parameter | Type | Description |
| --------- | ---- | ----------- |
| `df`      | —    | —           |

**Returns**

* pd.DataFrame: Original or scaled data

***

### `postprocess_reduced_data()`

```python
def postprocess_reduced_data(reduced_data, original_df)
```

Convert reduced data back to panel format.

**Parameters**

| Parameter      | Type | Description |
| -------------- | ---- | ----------- |
| `reduced_data` | —    | —           |
| `original_df`  | —    | —           |

***

### `dimensionality_reduction()`

```python
def dimensionality_reduction(
    df,
    method,
    explained_variance = 0.95,
    n_components = None,
    random_state = 42,
)
```

Apply dimensionality reduction technique.

**Parameters**

| Parameter            | Type | Description                                                                               |
| -------------------- | ---- | ----------------------------------------------------------------------------------------- |
| `df`                 | —    | pandas DataFrame                                                                          |
| `method`             | —    | str, dimensionality reduction method                                                      |
| `explained_variance` | —    | float, amount of variance to be explained (default: 0.95)                                 |
| `n_components`       | —    | int or None, number of components (takes precedence over explained\_variance if provided) |
| `random_state`       | —    | int, random state for reproducibility                                                     |

**Returns**

* reduced\_data: pandas DataFrame with reduced dimensions

***
