How to convert feature names (column names), resulted by tsfresh extract_features, to format, compatible with ComprehensiveFCParameters.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
To save and parse selected features in
tsfresh
, you can follow these steps:Saving Selected Features:
1.Extract Features: Use
tsfresh.extract_features
to extract a large set of features from your time series data.2.Select Features: Identify and select the features you want to save based on your requirements.
3.Save Selected Features: Save the selected features to a file (e.g., CSV) for future use.
Parsing Selected Features:
1.Load Selected Features: Load the previously saved selected features from the file.
2.Use Selected Features: Use the selected features as needed for further analysis or modeling.
Notes:
'feature1'
,'feature2'
, etc.) match exactly with the names in your extracted features DataFrame.pd.read_csv
in this example) based on the format you choose for saving the selected features.To save and parse selected features in `tsfresh`:
# Saving Selected Features
1. Extract Features:
“`python
from tsfresh import extract_features
extracted_features = extract_features(data, column_id=’id’, column_sort=’time’)
“`
2. Select Relevant Features:
“`python
from tsfresh import select_features
from tsfresh.utilities.dataframe_functions import impute
impute(extracted_features)
selected_features = select_features(extracted_features, y)
“`
3. Save Selected Features:
“`python
selected_features.to_csv(‘selected_features.csv’)
“`
# Parsing and Converting Feature Names
1. Load Selected Features:
“`python
import pandas as pd
selected_features = pd.read_csv(‘selected_features.csv’, index_col=0)
“`
2. Convert to Compatible Format:
“`python
from tsfresh.feature_extraction import ComprehensiveFCParameters
import re
def convert_feature_names(selected_features):
new_params = {}
for feature in selected_features.columns:
match = re.match(r'(.+?)__([^_]+)_(.+)’, feature)
if match:
feature_name, param, value = match.groups()
if feature_name not in new_params:
new_params[feature_name] = {param: [value]}
else:
new_params[feature_name].setdefault(param, []).append(value)
return new_params
compatible_format = convert_feature_names(selected_features)
Explanation
– Extract Features: Initial feature extraction.
– Select Features: Choose relevant features.
– Save to CSV: Save for future use.
– Convert Names: Format for `ComprehensiveFCParameters`.
This prepares features for further analysis or model training.