gtime.causality.ShiftedLinearCoefficient

class gtime.causality.ShiftedLinearCoefficient(min_shift: int = 1, max_shift: int = 10, target_col: str = 'y', dropna: bool = False, bootstrap_iterations: int = None)

Test the shifted linear fit coefficients between two or more time series.

Parameters
min_shiftint, optional, default: 1

The minimum number of shifts to check for.

max_shiftint, optional, default: 10

The maximum number of shifts to check for.

target_colstr, optional, default: 'y'

The column to use as the a reference (i.e., the column which is not shifted).

dropnabool, optional, default: False

Determines if the Nan values created by shifting are retained or dropped.

bootstrap_iterationsint, optional, default: None

If not None, compute the p_values of the test, by performing bootstrap.

Examples

>>> from gtime.causality.linear_coefficient import ShiftedLinearCoefficient
>>> import pandas.util.testing as testing
>>> data = testing.makeTimeDataFrame(freq="s")
>>> slc = ShiftedLinearCoefficient(target_col="A")
>>> slc.fit(data)
>>> slc.best_shifts_
y  A  B  C  D
x
A  3  6  8  5
B  9  9  4  1
C  8  2  4  9
D  3  9  4  3
>>> slc.max_corrs_
y         A         B         C         D
x
A  0.460236  0.420005  0.339370  0.267143
B  0.177856  0.300350  0.367150  0.550490
C  0.484860  0.263036  0.456046  0.251342
D  0.580068  0.344688  0.253626  0.256220

Methods

fit(self, data)

Create the DataFrame of shifts of each time series which maximize the shifted

fit_transform(self, X[, y])

Fit to data, then transform it.

get_params(self[, deep])

Get parameters for this estimator.

set_params(self, \*\*params)

Set the parameters of this estimator.

transform(self, data)

Shifts each input time series by the amount which optimizes correlation with the selected ‘y’ column.

__init__(self, min_shift:int=1, max_shift:int=10, target_col:str='y', dropna:bool=False, bootstrap_iterations:int=None)

Initialize self. See help(type(self)) for accurate signature.

fit(self, data:pandas.core.frame.DataFrame) → 'ShiftedLinearCoefficient'
Create the DataFrame of shifts of each time series which maximize the shifted

linear fit coefficients.

Parameters
datapd.DataFrame, shape (n_samples, n_time_series), required

The DataFrame containing the time-series on which to compute the shifted linear fit coefficients.

Returns
selfShiftedLinearCoefficient
fit_transform(self, X, y=None, **fit_params)

Fit to data, then transform it.

Fits transformer to X and y with optional parameters fit_params and returns a transformed version of X.

Parameters
Xnumpy array of shape [n_samples, n_features]

Training set.

ynumpy array of shape [n_samples]

Target values.

**fit_paramsdict

Additional fit parameters.

Returns
X_newnumpy array of shape [n_samples, n_features_new]

Transformed array.

get_params(self, deep=True)

Get parameters for this estimator.

Parameters
deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns
paramsmapping of string to any

Parameter names mapped to their values.

set_params(self, **params)

Set the parameters of this estimator.

The method works on simple estimators as well as on nested objects (such as pipelines). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.

Parameters
**paramsdict

Estimator parameters.

Returns
selfobject

Estimator instance.

transform(self, data:pandas.core.frame.DataFrame) → pandas.core.frame.DataFrame

Shifts each input time series by the amount which optimizes correlation with the selected ‘y’ column.

Parameters
datapd.DataFrame, shape (n_samples, n_time_series), required

The DataFrame containing the time series on which to perform the transformation.

Returns
data_tpd.DataFrame, shape (n_samples, n_time_series)

The DataFrame (Pivot table) of the shifts which maximize the correlation between each time series. The shift is indicated in rows.