# ❖ BootstrapSynthesizer

{% hint style="info" %}
❖ **SDV Enterprise Bundle**. This feature is available as part of the **XSynthesizers Bundle**, an optional add-on to SDV Enterprise. For more information, please visit the [XSynthesizers Bundle](https://docs.sdv.dev/sdv/explore/sdv-bundles/xsynthesizers) page.
{% endhint %}

The BootstrapSynthesizer is a synthesizer specifically designed to work when you only have a few rows of data — or if your data is "short and wide", containing more columns than rows. This synthesizer internally bootstraps your real data, and then uses the bootstrapped data to build a model. The modeling part is compatible with any other [single-table synthesizer](https://docs.sdv.dev/sdv/single-table-data/modeling/synthesizers).

```python
from sdv.single_table import BootstrapSynthesizer

synthesizer = BootstrapSynthesizer(metadata)
synthesizer.fit(data)

synthetic_data = synthesizer.sample(num_rows=10)
```

## Creating a synthesizer

When creating your synthesizer, you are required to pass in a [Metadata](https://docs.sdv.dev/sdv/single-table-data/data-preparation/creating-metadata) object as the first argument. All other parameters are optional. You can include them to customize the synthesizer.

```python
synthesizer = BootstrapSynthesizer(
    metadata, # required
    num_rows_bootstrap=1000,
    bootstrap_noise_amt=1.5,
    data_synthesizer='GaussianCopulaSynthesizer',
    enforce_min_max_values=True,
    synthesize_missing_values=False
)
```

### Parameter Reference

**`num_rows_bootstrap`** : Specify the number of additional rows to bootstrap before modeling the data.

<table data-header-hidden><thead><tr><th width="179"></th><th></th></tr></thead><tbody><tr><td>(default) <code>1000</code></td><td>Bootstrap the original data by creating 1000 rows of additional data</td></tr><tr><td><code>&#x3C;integer></code></td><td>Create the desired number of bootstrapped rows before building the model</td></tr></tbody></table>

**`bootstrap_noise_amount`** : The amount of noise to add when bootstrapping the data. Some noise is necessary to provide a greater diversity of data points for modeling.

<table data-header-hidden><thead><tr><th width="179"></th><th></th></tr></thead><tbody><tr><td>(default) <code>1.5</code></td><td>When bootstrapping the data, add noise that is equal to 1.5x the standard deviation of each row.</td></tr><tr><td><code>&#x3C;float></code></td><td>Add the desired amount of noise to the bootstrapped data. This is the multiplier to the standard deviation, so 1.5 means 1.5x the standard deviation, 2 means 2x the standard deviation, etc.</td></tr></tbody></table>

**`data_synthesizer`** : The single-table synthesizer to use when modeling the bootstrapped data.

<table data-header-hidden><thead><tr><th width="267.59375"></th><th></th></tr></thead><tbody><tr><td>(default) <code>'GaussianCopulaSynthesizer'</code></td><td>Use the <a href="gaussiancopulasynthesizer">GaussianCopulaSynthesizer</a> to build a model of the bootstrapped data</td></tr><tr><td><code>&#x3C;synthesizer_name></code></td><td>Supply a synthesizer name from the list of <a href="">single table synthesizers</a>. For example <code>'XGCSynthesizer'</code> or <code>'CTGANSynthesizer'</code>.</td></tr></tbody></table>

**`data_synthesizer_params`** : A dictionary of parameters to use for the synthesizer

<table data-header-hidden><thead><tr><th width="221.0078125"></th><th></th></tr></thead><tbody><tr><td>(default) <code>None</code></td><td>Use the default parameters for the synthesizer</td></tr><tr><td><code>&#x3C;dictionary></code></td><td>Update the default parameters for the synthesizer you've chosen by providing a dictionary of key/values pairs for each parameter. Refer to the docs for your synthesizer for possible parameters. For example, for <a href="gaussiancopulasynthesizer">GaussianCopulaSynthesizer</a> you can supply: <code>{'default_distribution': 'norm'}</code>.</td></tr></tbody></table>

**`enforce_min_max_values`**: Control whether the synthetic data should adhere to the same min/max boundaries set by the real data

<table data-header-hidden><thead><tr><th width="179"></th><th></th></tr></thead><tbody><tr><td>(default) <code>True</code></td><td>The synthetic data will contain numerical values that are within the ranges of the real data.</td></tr><tr><td><code>False</code></td><td>The synthetic data may contain numerical values that are less than or greater than the real data.</td></tr></tbody></table>

**`synthesize_missing_values`**: Control whether the synthetic data should include missing values.

<table data-header-hidden><thead><tr><th width="179"></th><th></th></tr></thead><tbody><tr><td>(default) <code>True</code></td><td>The synthetic data will contain missing values in roughly the same proportion as the original data</td></tr><tr><td><code>False</code></td><td>The synthetic data may should not contain any missing values for numerical and datetime columns.</td></tr></tbody></table>

### get\_parameters

Use this function to access the all parameters your synthesizer uses -- those you have provided as well as the default ones.

**Parameters** None

**Output** A dictionary with the parameter names and the values

```python
synthesizer.get_parameters()
```

```python
{
    'num_rows_bootstrap': 1000,
    'bootstrap_noise_amt': 1.5,
    'data_synthesizer': 'GaussianCopulaSynthesizer',
    'enforce_min_max_bounds': True,
    'synthesize_missing_values': False
}
```

{% hint style="info" %}
The returned parameters are a copy. Changing them will not affect the synthesizer.
{% endhint %}

### get\_metadata

Use this function to access the metadata object that you have included for the synthesizer

**Parameters** None

**Output** A [Metadata](https://docs.sdv.dev/sdv/concepts/metadata) object

```python
metadata = synthesizer.get_metadata()
```

{% hint style="info" %}
The returned metadata is a copy. Changing it will not affect the synthesizer.
{% endhint %}

## Learning from your data

To learn a machine learning model based on your real data, use the `fit` method.

### fit

**Parameters**

* (required) `data`: A [pandas DataFrame](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.html) object containing the real data that the machine learning model will learn from

**Output** (None)

```python
synthesizer.fit(data)
```

{% hint style="info" %}
**Technical Details:** This synthesizer internally bootstraps your real data by adding noise, and then uses the bootstrapped data to build a model. The modeling part is compatible with any other [single-table synthesizer](https://docs.sdv.dev/sdv/single-table-data/modeling/synthesizers).
{% endhint %}

## Saving your synthesizer

Save your trained synthesizer for future use.

### save

Use this function to save your trained synthesizer as a Python pickle file.

**Parameters**

* (required) `filepath`: A string describing the filepath where you want to save your synthesizer. Make sure this ends in `.pkl`&#x20;

**Output** (None) The file will be saved at the desired location

```python
synthesizer.save(
    filepath='my_synthesizer.pkl'
)
```

### load (utility function)

Use this utility function to load a trained synthesizer from a Python pickle file. After loading your synthesizer, you'll be able to sample synthetic data from it.

**Parameters**

* (required) `filepath`: A string describing the filepath of your saved synthesizer

**Output** Your synthesizer object

```python
from sdv.utils import load_synthesizer

synthesizer = load_synthesizer(
    filepath='my_synthesizer.pkl'
)
```

*This utility function works for any SDV synthesizer.*

## What's next?

After training your synthesizer, you can now sample synthetic data. See the [Sampling](https://docs.sdv.dev/sdv/single-table-data/sampling) section for more details.

```python
synthetic_data = synthesizer.sample(num_rows=10)
```

{% hint style="info" %}
**Want to improve your synthesizer?** Input logical rules in the form of constraints, and customize the transformations used for pre- and post-processing the data.

For more details, see [Customizations](https://docs.sdv.dev/sdv/single-table-data/modeling/customizations).
{% endhint %}

## FAQ

<details>

<summary>What does it mean to bootstrap data?</summary>

Bootstrapping data means creating more examples of training data using your original rows. Bootstrapping involves duplicating the original rows, and then adding some noise to the values in order to create a larger, more varied dataset.

This is necessary because the AI-based models expect a larger number of data points for accurate learning.

</details>
