> For the complete documentation index, see [llms.txt](https://seattle-university.gitbook.io/sdgne/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://seattle-university.gitbook.io/sdgne/smote-variants/sdd-smote.md).

# SDD SMOTE

This SMOTE variant, known as SDD (Sample Density Distribution) SMOTE, leverages a density distribution for generating synthetic instances in the minority class of imbalanced datasets. It considers both the density of existing minority class instances and the average distances within the minority class and between the minority and majority classes. The algorithm aims to address the class imbalance by focusing on regions of the feature space with lower density and larger distances, where real instances are sparser. It uses a density-based approach to prioritize the generation of synthetic samples in under-represented regions. The key parameter is the radius, which influences the neighborhood for density and distance calculations. SDD SMOTE contributes to enhancing the diversity and representation of the minority class in the dataset.

```python
from sdgne.datagenerator.smote import SDD_SMOTE

minority_column_label = 'class'
minority_class_label = 0

synthesizer = SDD_SMOTE(dataset,minority_column_label,minority_class_label)

synthesize_data = synthesizer.data_generator()
```

## Importing SMOTE

```python
from sdgne.datagenerator.smote import SDD_SMOTE
```

***

## Creating a synthesizer

```python
synthesizer = SDD_SMOTE(dataset, minority_column_label, minority_class_label)
```

### Parameters

<table data-header-hidden data-full-width="false"><thead><tr><th width="216.66666666666669">variable</th><th width="140">type</th><th>datatype</th><th>info</th></tr></thead><tbody><tr><td>dataset</td><td>required</td><td>pd.Dataframe</td><td>Represents a pandas data frame containing both, the original minority and the original majority data.</td></tr><tr><td>minority_column_label</td><td>required</td><td>string</td><td>Represents the column label. Eg. 'class', 'output'</td></tr><tr><td>minority_class_label</td><td>required</td><td>string</td><td>Represents the minority class label. Eg. '1', '0'</td></tr></tbody></table>

### Returns

An instance of class SDD\_SMOTE.

## Synthetic Data Generation

### data\_generator()

The data generator function generates synthetic data using the synthesizer. It has an option parameter  `num_to_synthesize.`

* If `num_to_synthesize` is not defined, data\_generator by default generates the \`n\` number of synthetic data such that the majority data and minority datasets get balanced.
* If `num_to_synthesize` is defined and the dataset is already balanced, data\_generator generates 2 \* Number of original minority data.
* If `num_to_synthesize` is defined and the dataset is not balanced, it generates synthetic data equal to the value passed.

```python
synthesized_data = synthesizer.data_generator(no_of_syntetic_data)
```

### Parameters

<table data-header-hidden><thead><tr><th width="222">variable</th><th width="154">type</th><th width="107">datatype</th><th>info</th></tr></thead><tbody><tr><td><code>num_to_synthesize</code></td><td>optional (default: None)</td><td>integer</td><td>Represents the number of synthetic data to be generated.</td></tr></tbody></table>

### Returns

A pandas data frame that combines original data and synthetic data.

### Usage

`synthesizer.data_generator()`

`synthesizer.data_generator(num_to_synthesize=100)`
