gtime.causality.ShiftedPearsonCorrelation¶
-
class
gtime.causality.ShiftedPearsonCorrelation(min_shift: int = 1, max_shift: int = 10, target_col: str = None, dropna: bool = False, bootstrap_iterations: int = None, permutation_iterations: int = None)¶ Class responsible for assessing the shifted Pearson correlations (PPMCC) between two or more series. For more info about the test, click here.
Parameters: - min_shift : int, optional, default:
1 The minimum number of shifts to check for.
- max_shift : int, optional, default:
10 The maximum number of shifts to check for.
- target_col : str, optional, default:
None The column to use as the a reference (i.e., the columns which is not shifted).
- dropna : bool, optional, default:
False Determines if the Nan values created by shifting are retained or dropped.
- bootstrap_iterations : int, optional, default:
None If not None, compute the p_values of the test, by performing bootstrapping of the original data (sampling with replacement).
- permutation_iterations : int, optional, default:
None If not None, compute the p_values of the test, by performing permutations of the original data.
Examples
>>> from gtime.causality.pearson_correlation import ShiftedPearsonCorrelation >>> import pandas.util.testing as testing >>> data = testing.makeTimeDataFrame(freq="s") >>> spc = ShiftedPearsonCorrelation(target_col="A") >>> spc.fit(data) >>> spc.best_shifts_ y A B C D x A 8 9 6 5 B 7 4 4 6 C 3 4 9 9 D 7 1 9 1 >>> spc.max_corrs_ y A B C D x A 0.383800 0.260627 0.343628 0.360151 B 0.311608 0.307203 0.255969 0.298523 C 0.373613 0.267335 0.211913 0.140034 D 0.496535 0.204770 0.402473 0.310065
Methods
fit(self, data)Create the dataframe of shifts of each time series which maximize the 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 ‘target_col’ column. -
__init__(self, min_shift: int = 1, max_shift: int = 10, target_col: str = None, dropna: bool = False, bootstrap_iterations: int = None, permutation_iterations: int = None)¶ Initialize self. See help(type(self)) for accurate signature.
-
fit(self, data: pandas.core.frame.DataFrame) → 'ShiftedPearsonCorrelation'¶ - Create the dataframe of shifts of each time series which maximize the
- Pearson correlation (PPMCC).
Parameters: - data : pd.DataFrame, shape (n_samples, n_time_series), required
The DataFrame containing the time series on which to compute the shifted correlations.
Returns: - self :
ShiftedPearsonCorrelation
-
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: - X : numpy array of shape [n_samples, n_features]
Training set.
- y : numpy array of shape [n_samples]
Target values.
- **fit_params : dict
Additional fit parameters.
Returns: - X_new : numpy array of shape [n_samples, n_features_new]
Transformed array.
-
get_params(self, deep=True)¶ Get parameters for this estimator.
Parameters: - deep : bool, default=True
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Returns: - params : mapping 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: - **params : dict
Estimator parameters.
Returns: - self : object
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 ‘target_col’ column. If no target column is specified, the first column of the DataFrame is taken as the target.
Parameters: - data : pd.DataFrame, shape (n_samples, n_time_series), required
The DataFrame containing the time series on which to perform the transformation.
Returns: - data_t : pd.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.
- min_shift : int, optional, default: