How to extract features with tsfresh in one series

342 Views Asked by At

My target is the state of the robot after hours. There is one robot. So id_column is 1 for every row. Doing so will result in an error in extract_features. How can I use tsfresh with one series?

1

There are 1 best solutions below

3
On

If you're trying to apply tsfresh on a single time series , you won't need an ID column because there's just one series. So, instead of thinking about how to hack around the requirement for multiple IDs, just use your data directly.

Here's an easy peasy lemon squeezy way of doing it:

from tsfresh import extract_features

# Assuming your pandas series is named 'series'
extracted_features = extract_features(series, column_id=None , column_sort=None)

What this code does is it extracts the features directly from your series. Remember, tsfresh loves a pandas Series object , so make sure your data is in that format.

However, if you do have a DataFrame and still want to treat it as a single time series, make sure it's formatted correctly. You'll want your DataFrame to have two columns: one for time , and one for the value. Something like this:

  time  value
0     0    1.1
1     1    2.3
2     2    3.1
...

Once you've got your DataFrame in shipshape , you can use the extract_features function like this:

from tsfresh import extract_features

# Assuming your dataframe is named 'df'
extracted_features = extract_features(df, column_id=None , column_sort='time')

Here , column_sort is 'time' since that's the name of our time column in the DataFrame. If your column is named something else, just replace 'time' with the name of your time column.