Transformations


source

box_cox_transform


def box_cox_transform(
    x, # The input data to be transformed.
    shift:bool=False, # Whether to shift the data by 1 before transformation to handle zeros.
    box_cox_lmda:float=None, # The lambda parameter for the Box-Cox transformation. If None, it will be estimated from the data.
): # The Box-Cox transformed data and the lambda used for transformation.

Applies a Box-Cox transformation to a series x.

Type Default Details
x The input data to be transformed.
shift bool False Whether to shift the data by 1 before transformation to handle zeros.
box_cox_lmda float None The lambda parameter for the Box-Cox transformation. If None, it will be estimated from the data.
Returns The Box-Cox transformed data and the lambda used for transformation.

source

back_box_cox_transform


def back_box_cox_transform(
    y_pred:np.ndarray, # The Box-Cox transformed forecast to be back-transformed.
    lmda:float, # The lambda parameter used in the Box-Cox transformation.
    shift:bool=False, # Whether the original data was shifted by 1 before transformation.
    box_cox_biasadj:bool=False, # Whether to apply bias adjustment to the back-transformed forecast.
)->np.ndarray: # The back-transformed forecast.

Inverse Box-Cox transform.

Type Default Details
y_pred np.ndarray The Box-Cox transformed forecast to be back-transformed.
lmda float The lambda parameter used in the Box-Cox transformation.
shift bool False Whether the original data was shifted by 1 before transformation.
box_cox_biasadj bool False Whether to apply bias adjustment to the back-transformed forecast.
Returns np.ndarray The back-transformed forecast.

source

fourier_terms


def fourier_terms(
    index:Union[pd.Index, tuple], # Either a pandas Index directly (recommended), or a (start, end) tuple of integers or datetime strings.
    period:Union[int, float], # The period of the seasonality (e.g., 365.25/7 for weekly yearly seasonality).
    num_terms:int, # The number of Fourier term pairs (sin + cos) to generate.
    frequency:Optional[str]=None, # Frequency string (e.g., "W-SAT", "D", "M", "W"). Only relevant when index is a (start, end) tuple.
    t_start:Optional[int]=None, # Starting position of t. Only used when index is a (start, end) tuple. Use len(train_index) to ensure continuity between train and test.
)->pd.DataFrame: # DataFrame of Fourier terms aligned to the provided index.

Generate Fourier terms for a given index or (start, end) tuple.

Type Default Details
index Union[pd.Index, tuple] Either a pandas Index directly (recommended), or a (start, end) tuple of integers or datetime strings.
period Union[int, float] The period of the seasonality (e.g., 365.25/7 for weekly yearly seasonality).
num_terms int The number of Fourier term pairs (sin + cos) to generate.
frequency Optional[str] None Frequency string (e.g., “W-SAT”, “D”, “M”, “W”). Only relevant when index is a (start, end) tuple.
t_start Optional[int] None Starting position of t. Only used when index is a (start, end) tuple. Use len(train_index) to ensure continuity between train and test.
Returns pd.DataFrame DataFrame of Fourier terms aligned to the provided index.

source

rolling_mean


def rolling_mean(
    window_size:int, # The size of the rolling window.
    shift:int=1, # The number of periods to shift the data before applying the rolling mean (default is 1).
    min_samples:int=1, # The minimum number of observations in the window required to have a value (default is 1).
):

A class to compute the rolling mean of a time series with specified window size and shift.

Type Default Details
window_size int The size of the rolling window.
shift int 1 The number of periods to shift the data before applying the rolling mean (default is 1).
min_samples int 1 The minimum number of observations in the window required to have a value (default is 1).
Returns

source

rolling_quantile


def rolling_quantile(
    window_size:int, # The size of the rolling window.
    quantile:float, # The quantile to compute (between 0 and 1).
    shift:int=1, # The number of periods to shift the data before applying the rolling quantile (default is 1).
    min_samples:int=1, # The minimum number of observations in the window required to have a value (default is 1).
):

A class to compute the rolling quantile of a time series with specified window size, quantile, and shift.

Type Default Details
window_size int The size of the rolling window.
quantile float The quantile to compute (between 0 and 1).
shift int 1 The number of periods to shift the data before applying the rolling quantile (default is 1).
min_samples int 1 The minimum number of observations in the window required to have a value (default is 1).
Returns

source

rolling_std


def rolling_std(
    window_size:int, # The size of the rolling window.
    shift:int=1, # The number of periods to shift the data before applying the rolling standard deviation (default is 1).
    min_samples:int=1, # The minimum number of observations in the window required to have a value (default is 1).
):

A class to compute the rolling standard deviation of a time series with specified window size and shift.

Type Default Details
window_size int The size of the rolling window.
shift int 1 The number of periods to shift the data before applying the rolling standard deviation (default is 1).
min_samples int 1 The minimum number of observations in the window required to have a value (default is 1).
Returns

source

rolling_min


def rolling_min(
    window_size:int, # The size of the rolling window.
    shift:int=1, # The number of periods to shift the data before applying the rolling minimum (default is 1).
    min_samples:int=1, # The minimum number of observations in the window required to have a value (default is 1).
):

A class to compute the rolling minimum of a time series with specified window size and shift.

Type Default Details
window_size int The size of the rolling window.
shift int 1 The number of periods to shift the data before applying the rolling minimum (default is 1).
min_samples int 1 The minimum number of observations in the window required to have a value (default is 1).
Returns

source

rolling_max


def rolling_max(
    window_size:int, # The size of the rolling window.
    shift:int=1, # The number of periods to shift the data before applying the rolling maximum (default is 1).
    min_samples:int=1, # The minimum number of observations in the window required to have a value (default is 1).
):

A class to compute the rolling maximum of a time series with specified window size and shift.

Type Default Details
window_size int The size of the rolling window.
shift int 1 The number of periods to shift the data before applying the rolling maximum (default is 1).
min_samples int 1 The minimum number of observations in the window required to have a value (default is 1).
Returns

source

expanding_mean


def expanding_mean(
    shift:int=1
):

A class to compute the expanding mean of a time series with specified shift.

Type Default Details
shift int 1
Returns

source

expanding_std


def expanding_std(
    shift:int=1, # The number of periods to shift the data before applying the expanding standard deviation (default is 1).
):

A class to compute the expanding standard deviation of a time series with specified shift.

Type Default Details
shift int 1 The number of periods to shift the data before applying the expanding standard deviation (default is 1).
Returns

source

expanding_quantile


def expanding_quantile(
    shift:int=1, # The number of periods to shift the data before applying the expanding quantile (default is 1).
    quantile:float=0.5, # The quantile to compute (between 0 and 1) (default is 0.5).
):

A class to compute the expanding quantile of a time series with specified shift and quantile.

Type Default Details
shift int 1 The number of periods to shift the data before applying the expanding quantile (default is 1).
quantile float 0.5 The quantile to compute (between 0 and 1) (default is 0.5).
Returns