Skip to content

Bases: BaseSynthesizer

Source code in ydata/sdk/synthesizers/timeseries.py
class TimeSeriesSynthesizer(BaseSynthesizer):

    def sample(self, n_entities: Optional[int] = None) -> pdDataFrame:
        """Sample from a [`TimeSeriesSynthesizer`][ydata.sdk.synthesizers.TimeSeriesSynthesizer] instance.

        If a training dataset was not using any `entity` column, the Synthesizer assumes a single entity.
        A [`TimeSeriesSynthesizer`][ydata.sdk.synthesizers.TimeSeriesSynthesizer] always sample the full trajectory of its entities.

        Arguments:
            n_entities (int): (optional) number of entities to sample. If `None`, uses the same number of entities as in the original dataset.

        Returns:
            synthetic data
        """
        if n_entities is not None and n_entities < 1:
            raise InputError("Parameter 'n_entities' must be greater than 0")

        return self._sample(payload={"numberOfRecords": n_entities})

    def fit(self, X: Union[DataSource, pdDataFrame],
            sortbykey: Optional[Union[str, List[str]]],
            privacy_level: PrivacyLevel = PrivacyLevel.HIGH_FIDELITY,
            entity_id_cols: Optional[Union[str, List[str]]] = None,
            generate_cols: Optional[List[str]] = None,
            exclude_cols: Optional[List[str]] = None,
            dtypes: Optional[Dict[str, Union[str, DataType]]] = None,
            target: Optional[str] = None,
            name: Optional[str] = None,
            anonymize: Optional[dict] = None) -> None:
        """Fit the synthesizer.

        The synthesizer accepts as training dataset either a pandas [`DataFrame`][pandas.DataFrame] directly or a YData [`DataSource`][ydata.sdk.datasources.DataSource].

        Arguments:
            X (Union[DataSource, pandas.DataFrame]): Training dataset
            sortbykey (Union[str, List[str]]): column(s) to use to sort timeseries datasets
            privacy_level (PrivacyLevel): Synthesizer privacy level (defaults to high fidelity)
            entity_id_cols (Union[str, List[str]]): (optional) columns representing entities ID
            generate_cols (List[str]): (optional) columns that should be synthesized
            exclude_cols (List[str]): (optional) columns that should not be synthesized
            dtypes (Dict[str, Union[str, DataType]]): (optional) datatype mapping that will overwrite the datasource metadata column datatypes
            target (Optional[str]): (optional) Metadata associated to the datasource
            name (Optional[str]): (optional) Synthesizer instance name
            anonymize (Optional[str]): (optional) fields to anonymize and the anonymization strategy
        """
        BaseSynthesizer.fit(self, X=X, datatype=DataSourceType.TIMESERIES, sortbykey=sortbykey,
                            entity_id_cols=entity_id_cols, generate_cols=generate_cols, exclude_cols=exclude_cols,
                            dtypes=dtypes, target=target, name=name, anonymize=anonymize, privacy_level=privacy_level)

    def __repr__(self):
        if self._model is not None:
            return self._model.__repr__()
        else:
            return "TimeSeriesSynthesizer(Not Initialized)"

fit(X, sortbykey, privacy_level=PrivacyLevel.HIGH_FIDELITY, entity_id_cols=None, generate_cols=None, exclude_cols=None, dtypes=None, target=None, name=None, anonymize=None)

Fit the synthesizer.

The synthesizer accepts as training dataset either a pandas DataFrame directly or a YData DataSource.

Parameters:

Name Type Description Default
X Union[DataSource, pandas.DataFrame]

Training dataset

required
sortbykey Union[str, List[str]]

column(s) to use to sort timeseries datasets

required
privacy_level PrivacyLevel

Synthesizer privacy level (defaults to high fidelity)

PrivacyLevel.HIGH_FIDELITY
entity_id_cols Union[str, List[str]]

(optional) columns representing entities ID

None
generate_cols List[str]

(optional) columns that should be synthesized

None
exclude_cols List[str]

(optional) columns that should not be synthesized

None
dtypes Dict[str, Union[str, DataType]]

(optional) datatype mapping that will overwrite the datasource metadata column datatypes

None
target Optional[str]

(optional) Metadata associated to the datasource

None
name Optional[str]

(optional) Synthesizer instance name

None
anonymize Optional[str]

(optional) fields to anonymize and the anonymization strategy

None
Source code in ydata/sdk/synthesizers/timeseries.py
def fit(self, X: Union[DataSource, pdDataFrame],
        sortbykey: Optional[Union[str, List[str]]],
        privacy_level: PrivacyLevel = PrivacyLevel.HIGH_FIDELITY,
        entity_id_cols: Optional[Union[str, List[str]]] = None,
        generate_cols: Optional[List[str]] = None,
        exclude_cols: Optional[List[str]] = None,
        dtypes: Optional[Dict[str, Union[str, DataType]]] = None,
        target: Optional[str] = None,
        name: Optional[str] = None,
        anonymize: Optional[dict] = None) -> None:
    """Fit the synthesizer.

    The synthesizer accepts as training dataset either a pandas [`DataFrame`][pandas.DataFrame] directly or a YData [`DataSource`][ydata.sdk.datasources.DataSource].

    Arguments:
        X (Union[DataSource, pandas.DataFrame]): Training dataset
        sortbykey (Union[str, List[str]]): column(s) to use to sort timeseries datasets
        privacy_level (PrivacyLevel): Synthesizer privacy level (defaults to high fidelity)
        entity_id_cols (Union[str, List[str]]): (optional) columns representing entities ID
        generate_cols (List[str]): (optional) columns that should be synthesized
        exclude_cols (List[str]): (optional) columns that should not be synthesized
        dtypes (Dict[str, Union[str, DataType]]): (optional) datatype mapping that will overwrite the datasource metadata column datatypes
        target (Optional[str]): (optional) Metadata associated to the datasource
        name (Optional[str]): (optional) Synthesizer instance name
        anonymize (Optional[str]): (optional) fields to anonymize and the anonymization strategy
    """
    BaseSynthesizer.fit(self, X=X, datatype=DataSourceType.TIMESERIES, sortbykey=sortbykey,
                        entity_id_cols=entity_id_cols, generate_cols=generate_cols, exclude_cols=exclude_cols,
                        dtypes=dtypes, target=target, name=name, anonymize=anonymize, privacy_level=privacy_level)

sample(n_entities=None)

Sample from a TimeSeriesSynthesizer instance.

If a training dataset was not using any entity column, the Synthesizer assumes a single entity. A TimeSeriesSynthesizer always sample the full trajectory of its entities.

Parameters:

Name Type Description Default
n_entities int

(optional) number of entities to sample. If None, uses the same number of entities as in the original dataset.

None

Returns:

Type Description
pdDataFrame

synthetic data

Source code in ydata/sdk/synthesizers/timeseries.py
def sample(self, n_entities: Optional[int] = None) -> pdDataFrame:
    """Sample from a [`TimeSeriesSynthesizer`][ydata.sdk.synthesizers.TimeSeriesSynthesizer] instance.

    If a training dataset was not using any `entity` column, the Synthesizer assumes a single entity.
    A [`TimeSeriesSynthesizer`][ydata.sdk.synthesizers.TimeSeriesSynthesizer] always sample the full trajectory of its entities.

    Arguments:
        n_entities (int): (optional) number of entities to sample. If `None`, uses the same number of entities as in the original dataset.

    Returns:
        synthetic data
    """
    if n_entities is not None and n_entities < 1:
        raise InputError("Parameter 'n_entities' must be greater than 0")

    return self._sample(payload={"numberOfRecords": n_entities})

PrivacyLevel

Bases: Enum

Privacy level exposed to the end-user.

BALANCED_PRIVACY_FIDELITY = auto() class-attribute

Balanced privacy/fidelity

HIGH_FIDELITY = auto() class-attribute

High fidelity

HIGH_PRIVACY = auto() class-attribute

High privacy