time_series_regularizer#

Transformer that regularizes a dataset with an uninferrable offset frequency for time series problems.

Module Contents#

Classes Summary#

TimeSeriesRegularizer

Transformer that regularizes an inconsistently spaced datetime column.

Contents#

class evalml.pipelines.components.transformers.preprocessing.time_series_regularizer.TimeSeriesRegularizer(time_index=None, frequency_payload=None, window_length=4, threshold=0.4, random_seed=0, **kwargs)[source]#

Transformer that regularizes an inconsistently spaced datetime column.

If X is passed in to fit/transform, the column time_index will be checked for an inferrable offset frequency. If the time_index column is perfectly inferrable then this Transformer will do nothing and return the original X and y.

If X does not have a perfectly inferrable frequency but one can be estimated, then X and y will be reformatted based on the estimated frequency for time_index. In the original X and y passed: - Missing datetime values will be added and will have their corresponding columns in X and y set to None. - Duplicate datetime values will be dropped. - Extra datetime values will be dropped. - If it can be determined that a duplicate or extra value is misaligned, then it will be repositioned to take the place of a missing value.

This Transformer should be used before the TimeSeriesImputer in order to impute the missing values that were added to X and y (if passed).

If used on multiseries dataset, works specifically on unstacked datasets.

Parameters
  • time_index (string) – Name of the column containing the datetime information used to order the data, required. Defaults to None.

  • frequency_payload (tuple) – Payload returned from Woodwork’s infer_frequency function where debug is True. Defaults to None.

  • window_length (int) – The size of the rolling window over which inference is conducted to determine the prevalence of uninferrable frequencies.

  • 5. (Lower values make this component more sensitive to recognizing numerous faulty datetime values. Defaults to) –

  • threshold (float) – The minimum percentage of windows that need to have been able to infer a frequency. Lower values make this component more

  • 0.8. (sensitive to recognizing numerous faulty datetime values. Defaults to) –

  • random_seed (int) – Seed for the random number generator. This transformer performs the same regardless of the random seed provided.

  • 0. (Defaults to) –

Raises

ValueError – if the frequency_payload parameter has not been passed a tuple

Attributes

hyperparameter_ranges

{}

modifies_features

True

modifies_target

True

name

Time Series Regularizer

training_only

True

Methods

clone

Constructs a new component with the same parameters and random state.

default_parameters

Returns the default parameters for this component.

describe

Describe a component and its parameters.

fit

Fits the TimeSeriesRegularizer.

fit_transform

Fits on X and transforms X.

load

Loads component at file path.

needs_fitting

Returns boolean determining if component needs fitting before calling predict, predict_proba, transform, or feature_importances.

parameters

Returns the parameters which were used to initialize the component.

save

Saves component at file path.

transform

Regularizes a dataframe and target data to an inferrable offset frequency.

update_parameters

Updates the parameter dictionary of the component.

clone(self)#

Constructs a new component with the same parameters and random state.

Returns

A new instance of this component with identical parameters and random state.

default_parameters(cls)#

Returns the default parameters for this component.

Our convention is that Component.default_parameters == Component().parameters.

Returns

Default parameters for this component.

Return type

dict

describe(self, print_name=False, return_dict=False)#

Describe a component and its parameters.

Parameters
  • print_name (bool, optional) – whether to print name of component

  • return_dict (bool, optional) – whether to return description as dictionary in the format {“name”: name, “parameters”: parameters}

Returns

Returns dictionary if return_dict is True, else None.

Return type

None or dict

fit(self, X, y=None)[source]#

Fits the TimeSeriesRegularizer.

Parameters
  • X (pd.DataFrame) – The input training data of shape [n_samples, n_features].

  • y (pd.Series, optional) – The target training data of length [n_samples].

Returns

self

Raises
  • ValueError – if self.time_index is None, if X and y have different lengths, if time_index in X does not have an offset frequency that can be estimated

  • TypeError – if the time_index column is not of type Datetime

  • KeyError – if the time_index column doesn’t exist

fit_transform(self, X, y=None)#

Fits on X and transforms X.

Parameters
  • X (pd.DataFrame) – Data to fit and transform.

  • y (pd.Series) – Target data.

Returns

Transformed X.

Return type

pd.DataFrame

Raises

MethodPropertyNotFoundError – If transformer does not have a transform method or a component_obj that implements transform.

static load(file_path)#

Loads component at file path.

Parameters

file_path (str) – Location to load file.

Returns

ComponentBase object

needs_fitting(self)#

Returns boolean determining if component needs fitting before calling predict, predict_proba, transform, or feature_importances.

This can be overridden to False for components that do not need to be fit or whose fit methods do nothing.

Returns

True.

property parameters(self)#

Returns the parameters which were used to initialize the component.

save(self, file_path, pickle_protocol=cloudpickle.DEFAULT_PROTOCOL)#

Saves component at file path.

Parameters
  • file_path (str) – Location to save file.

  • pickle_protocol (int) – The pickle data stream format.

transform(self, X, y=None)[source]#

Regularizes a dataframe and target data to an inferrable offset frequency.

A ‘clean’ X and y (if y was passed in) are created based on an inferrable offset frequency and matching datetime values with the original X and y are imputed into the clean X and y. Datetime values identified as misaligned are shifted into their appropriate position.

Parameters
  • X (pd.DataFrame) – The input training data of shape [n_samples, n_features].

  • y (pd.Series, optional) – The target training data of length [n_samples].

Returns

Data with an inferrable time_index offset frequency.

Return type

(pd.DataFrame, pd.Series)

update_parameters(self, update_dict, reset_fit=True)#

Updates the parameter dictionary of the component.

Parameters
  • update_dict (dict) – A dict of parameters to update.

  • reset_fit (bool, optional) – If True, will set _is_fitted to False.