pyhctsa.calculator.FeatureCalculator

class pyhctsa.calculator.FeatureCalculator(config_path=None)

A configuration-driven feature extraction calculator for time series data.

config

The parsed YAML configuration containing feature definitions.

Type:

dict

feature_funcs

A dictionary mapping feature labels to their corresponding callable functions.

Type:

dict

Parameters:
config_path : str or None, optional

Path to the YAML configuration file. If None, uses the default ‘hctsa.yaml’ configuration file in the package configurations directory.

Notes

Besides the operation’s own arguments, each entry of a feature’s configs list may carry these meta keys (not passed to the function):

  • zscore: True: z-score the series first (label gets no suffix; without it, _raw);

  • abs: True: take the absolute value last (suffix _abs);

  • preprocess: one more input transform, applied to the (z-scored) series before abs; its label suffix follows _abs. The values, with the hctsa input each reproduces:

    • decimate_ac1e (suffix _dec): zscore(BF_PreProcess(x_z, 'decimate_ac1e')). The z-scored series is decimated to one sample per floored 1/e autocorrelation time and z-scored again. If that time cannot be determined (e.g. the ACF never falls to 1/e), or fewer than 3 samples would remain (or fewer than the operation’s min_length), the feature is NaN. See pyhctsa.utils.decimate_ac1e();

    • diff1 (_diff1): diff(x_z);

    • zscore_abs (_mag): zscore(abs(x_z)); zscore_sign (_sign): zscore(sign(x_z)). (abs: True alone is abs(x_z).)

  • select / exclude: keep or drop keys of a dict-valued output.

A feature’s entry (alongside configs) may also give min_length: the shortest series on which it is defined (an int, or an expression in its parameters such as "tau + 1"; see _MIN_LENGTH_NAMESPACE for the helpers it may use). It applies to the series the function receives (after zscore/preprocess); for a shorter series every output of that feature is NaN, so the set of feature columns never depends on the length. The minima are listed in min_lengths. field_min_length (a mapping {field: int or expression}; a field name may contain {k}, an integer the expression can use) gives single fields of a dict output a larger minimum: below it that field alone is NaN (field_min_lengths).

Examples

>>> fc = FeatureCalculator()  # Load default configuration
>>> x = np.random.randn(1000)
>>> df = fc.extract(x)
__init__(config_path=None)

Initialises a FeatureCalculator instance.

Parameters:
config_path : str or None, optional

Path to the YAML configuration file. If None, uses the default configuration.

Methods

__init__([config_path])

Initialises a FeatureCalculator instance.

extract(data[, labels, verbose, distributor])

Run the configured feature extractor over one or more time series and return a single tidy pandas.DataFrame.

save(path, values[, meta])

Write values (the DataFrame the last extract() returned) together with its quality, errors and calc_time to path.