Skip to content

Calculate mean_n_absolute_max for all three configured maxima - #1128

Open
VenishPaneliya wants to merge 1 commit into
blue-yonder:mainfrom
VenishPaneliya:fix-mean-n-absolute-max-params
Open

Calculate mean_n_absolute_max for all three configured maxima#1128
VenishPaneliya wants to merge 1 commit into
blue-yonder:mainfrom
VenishPaneliya:fix-mean-n-absolute-max-params

Conversation

@VenishPaneliya

Copy link
Copy Markdown

Summary

In ComprehensiveFCParameters, the settings for mean_n_absolute_max are written as a single dictionary that repeats the same key:

"mean_n_absolute_max": [
    {
        "number_of_maxima": 3,
        "number_of_maxima": 5,
        "number_of_maxima": 7,
    }
],

A dict literal keeps only the last value for a repeated key, so this collapses to [{"number_of_maxima": 7}]. Only one feature is requested instead of three, and the settings for 3 and 5 are silently dropped.

Every neighbouring entry in the same block builds its parameter list with a comprehension (lempel_ziv_complexity, fourier_entropy, permutation_entropy, matrix_profile), which is what makes the intent here clear — three separate settings, not one dictionary.

Reproduction

On released tsfresh 0.21.2:

from tsfresh.feature_extraction.settings import ComprehensiveFCParameters

fset = ComprehensiveFCParameters()
print(fset["mean_n_absolute_max"])
# [{'number_of_maxima': 7}]          <- expected 3 entries

End to end, the two other features never get calculated:

import pandas as pd
from tsfresh import extract_features
from tsfresh.feature_extraction.settings import ComprehensiveFCParameters

df = pd.DataFrame({"id": [1]*12, "time": range(12),
                   "value": [3,1,4,1,5,9,2,6,5,3,5,8]})
fc = {"mean_n_absolute_max": ComprehensiveFCParameters()["mean_n_absolute_max"]}
X = extract_features(df, column_id="id", column_sort="time",
                     default_fc_parameters=fc, disable_progressbar=True, n_jobs=0)
print(list(X.columns))
# ['value__mean_n_absolute_max__number_of_maxima_7']

After the change:

['value__mean_n_absolute_max__number_of_maxima_3',
 'value__mean_n_absolute_max__number_of_maxima_5',
 'value__mean_n_absolute_max__number_of_maxima_7']
# values: 7.6667, 6.6, 6.0  -- three genuinely different features

Changes

-                "mean_n_absolute_max": [
-                    {
-                        "number_of_maxima": 3,
-                        "number_of_maxima": 5,
-                        "number_of_maxima": 7,
-                    }
-                ],
+                "mean_n_absolute_max": [{"number_of_maxima": x} for x in [3, 5, 7]],

Tests

Added test_mean_n_absolute_max_correctly_configured, following the existing test_range_count_correctly_configured style. It asserts the configured maxima are [3, 5, 7]; before the change it fails with Lists differ: [7] != [3, 5, 7].

tests/units/feature_extraction/test_settings.py and test_extraction.py: 34 passed. black and isort --profile black applied to both changed files.

Note

Anyone using ComprehensiveFCParameters now gets two additional mean_n_absolute_max columns that were previously missing, so extracted feature matrices will be slightly wider. That is the intended set, but flagging it since it changes default output.

Incidentally, this is the same dictionary-key collapse that came up in #1072, where the reported list had the same shape — the copy in settings.py looks like it was missed at the time.

The parameters for mean_n_absolute_max were written as a single dictionary
repeating the same key:

    "mean_n_absolute_max": [
        {
            "number_of_maxima": 3,
            "number_of_maxima": 5,
            "number_of_maxima": 7,
        }
    ],

A dictionary literal keeps only the last value for a repeated key, so this
collapsed to [{"number_of_maxima": 7}] and ComprehensiveFCParameters asked
for one feature instead of three. Extracting with the comprehensive settings
silently produced only mean_n_absolute_max__number_of_maxima_7.

Use the same comprehension the neighbouring entries use so all three
settings survive.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant