pyhctsa.calculator.FeatureCalculator¶
-
class pyhctsa.calculator.FeatureCalculator(config_path=
None)¶ A configuration-driven feature extraction calculator for time series data.
- 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 ‘feature_config.yaml’ configuration file in the package configurations directory.
Notes
Besides the operation’s own arguments, each entry of a feature’s
configslist 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 beforeabs; its label suffix follows_abs. The values:decimate_ac1e(suffix_dec): withtauthe floored 1/e autocorrelation time, the series is decimated to one sample pertaufrom each of thetaustarting phases (x_z[p::tau],p = 0, ..., tau - 1), each subseries z-scored again (withzscore: True). The function is computed on every subseries that has at least 3 samples and at least the operation’smin_length, and its outputs are averaged over them (field by field, ignoring NaN). The feature is NaN iftaucannot be determined (e.g. the ACF never falls to 1/e) or no subseries qualifies. Seepyhctsa.utils.decimation_phases();decimate_ac1e-rank(_dec-rank): the same, withtauset from the ranks of the series (get_tau(x_z, 'ac1e-rank')), for features that depend on the data only through their order;detrend(_lindt): the least-squares line removed and the residual z-scored again (withzscore: True); NaN if the series is a line up to round-off;diff1(_diff1):diff(x_z);zscore_abs(_mag):zscore(abs(x_z));zscore_sign(_sign):zscore(sign(x_z)). (abs: Truealone isabs(x_z).)
select/exclude: keep or drop keys of a dict-valued output.
A feature’s entry (alongside
configs) may also givemin_length: the shortest series on which it is defined (an int, or an expression in its parameters such as"tau + 1"; see_MIN_LENGTH_NAMESPACEfor the helpers it may use). It applies to the series the function receives (afterzscore/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 inmin_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)Methods
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 lastextract()returned) together with itsquality,errorsandcalc_timetopath.-
extract(data, labels=
None, verbose=False, distributor=None)¶ Run the configured feature extractor over one or more time series and return a single tidy pandas.DataFrame.
- Parameters:¶
- data : ArrayLike or list[ArrayLike]¶
The input time series data. Two forms are accepted:
Single series: a 1-D array, a pandas Series, or a list or tuple of real numbers.
Multiple series: a 2-D array with one series per row, or a list or tuple of series (arrays, pandas Series, lists or tuples), which may differ in length.
A pandas DataFrame is not accepted, since it does not say whether its rows or its columns are the series: pass
df.to_numpy()(rows) ordf.to_numpy().T(columns).- labels : ArrayLike, list, str, int, or None, optional¶
Labels for each time series. The order of labels is assumed to match the order of the time series as passed in the data argument.
- verbose : bool, optional¶
Whether to print progress and timing information. Default is
False.- distributor : object, optional¶
Optional distributor for parallel computation.
- Returns:¶
A DataFrame with one row per input series and one column per feature. Every value is a float: a real, finite number, or NaN. Why a value is NaN is in
quality, which this call also sets, witherrorsandcalc_time:quality: auint8DataFrame of the same shape, oneQualitycode per value (0 good, 1 error, 2 NaN, 3 Inf, 4 -Inf, 5 complex, 6 empty, 7 link error, 8 non-scalar, 9 rejected input; seepyhctsa.quality).errors: one row per feature function that raised (instance,feature,error_type,message), and one per series rejected by the input check (featureisNone). The user’s home directory is replaced by~inmessage.calc_time: seconds per series and feature function.
A series that fails the input check (too short, constant, or containing NaN or Inf) is not computed, and its row is coded
Quality.REJECTED. If every series fails it, aValueErroris raised.A
UserWarning(one per call) says how many series consist almost entirely of repeated values, whose rank-, bin- and symbol-based features can change when the series is rescaled or shifted (see “Series with many repeated values” in the usage guide). It changes no value.- Return type:¶
pd.DataFrame
-
save(path, values, meta=
None)¶ Write
values(the DataFrame the lastextract()returned) together with itsquality,errorsandcalc_timetopath.The format follows the suffix:
.npz(no extra dependency) or.parquet(needs pyarrow). Read it back withpyhctsa.load_results().The file also records which feature set produced the values (
metaofload_results()): the pyhctsa version, the time of saving, the configuration (config_name, its file name only, andconfig_sha256, the SHA-256 of its text, which changes with any edit), the number of feature functions, whetherfeature_funcswas changed after the configuration built it (feature_functions_modified), and the operations skipped for missing optional dependencies (skipped_operations,missing_dependencies,n_skipped_feature_functions).metaadds to these, or overrides them.A file you share therefore shows the series labels (the index), the configuration’s file name and hash, the pyhctsa version, when it was saved and which optional packages were missing, besides the values, quality codes, errors and timings. pyhctsa records no file paths (not even
config_path), user names or host names. Themessagecolumn oferrorsholds each exception’s message, with the user’s home directory replaced by~(/Users/<name>/...becomes~/...). A message can still contain a path outside the home directory, or other text that the failing package or custom feature function chose to include.