You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Python的tsfresh中仅提取方差与标准差特征?

How to Calculate Only Specific Features for F_x in tsfresh

Hey there! I get that when you're starting out with tsfresh, narrowing down to exactly the features you need can feel a bit tricky. Let me break down how to adjust your code to only compute F_x__variance and F_x__standard_deviation:

The Core Idea

Instead of using ComprehensiveFCParameters() (which enables all possible features), you'll define a custom settings dictionary that explicitly specifies only the features you want for your F_x column. TSFresh uses this dictionary to know exactly which calculations to run.

Modified Code

Here's the adjusted version of your code:

from tsfresh import extract_relevant_features

# Define your custom settings: only keep variance and standard_deviation for F_x
custom_settings = {
    'F_x': {
        'variance': None,       # Use default parameters for variance
        'standard_deviation': None  # Use default parameters for standard deviation
    }
}

# Now extract only the specified features
features_filtered_direct = extract_relevant_features(
    df, 
    y, 
    column_id='id', 
    column_sort='time',
    default_fc_parameters=custom_settings  # Pass your custom settings here
)

What's Happening Here?

  • The custom_settings dictionary tells tsfresh: "For the column F_x, only calculate the variance and standard_deviation features."
  • Setting the feature values to None means we use the default parameters for those features (neither of these require extra configuration, so this works perfectly).
  • If you ever wanted to add parameters to a feature (like adjusting bins for a histogram feature), you'd replace None with a dictionary of parameters instead.

Bonus: If You Need Other Columns' Features Too

If you have other time series columns and want to keep their default features but only limit F_x to these two, you can start with a base settings object and modify it:

from tsfresh import extract_relevant_features
from tsfresh.feature_extraction import ComprehensiveFCParameters

# Start with all default features
settings = ComprehensiveFCParameters()
# Override F_x to only include your desired features
settings['F_x'] = {'variance': None, 'standard_deviation': None}

# Then use this modified settings object in extract_relevant_features
features_filtered_direct = extract_relevant_features(
    df, 
    y, 
    column_id='id', 
    column_sort='time',
    default_fc_parameters=settings
)

That should give you exactly the two features you're looking for without the extra 95! Let me know if you run into any snags.

内容的提问来源于stack exchange,提问作者Humaun Rashid Nayan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 06:58:59