Use TSFRESH-library to forecast values

4

1

Have some issue with understanding how to use TSFERSH-library (version 0.4.0) to forecast next N-values of particular series. Below my code:

    # load data train/test datasets        
    train, Y, test, YY = prepare_train_test()
    # add series ID         
    train['TS_ID'] = pd.Categorical(train['QTR_HR_START']).codes
    test['TS_ID'] = pd.Categorical(test['QTR_HR_START']).codes
    # add ordered id for concrete event of series
    for id in sorted(train['TS_ID'].unique()):
        train.ix[train.TS_ID == id, 'TIME_ORDER_ID'] =  pd.Categorical(train[train.TS_ID == id]['DATETIME']).codes
    for id in sorted(test['TS_ID'].unique()):
        test.ix[test.TS_ID == id, 'TIME_ORDER_ID'] = pd.Categorical(test[test.TS_ID == id]['DATETIME']).codes
    # perform feature extraction for my signal
    extraction_settings = FeatureExtractionSettings()
    extraction_settings.IMPUTE = impute  # Fill in Infs and NaNs
    X = extract_features(train, column_id='TS_ID', feature_extraction_settings=extraction_settings).values
    XT = extract_features(test, column_id='TS_ID', feature_extraction_settings=extraction_settings).values

    # there should be as example 
    # model = xgb.DMatrix(X, label=Y, missing=np.nan)
    # model.fit()
    # model.predict(XT)

However, after line X = extract_features(...) I see at debugger following results enter image description here

It's mean that initial X-dataset/features (shape=(722,10) were transformed to shape (80, 1899).

Where does '80' come from? I guess from train.TS_ID comes. But my XT-dataset still contains 722-rows (9 days * 80 different series per day).

So, how can I predict for 9 days in advance? or is there only forecast for next period?

SpanishBoy

Posted 2016-11-12T14:35:25.700

Reputation: 517

Which version of tsfresh are you using? – MaxBenChrist – 2016-12-25T23:12:23.370

The latest one - 0.4 – SpanishBoy – 2016-12-26T10:28:56.637

From tsfresh, you get a feature matrix with one row for each time series id. You will then have to shift your feature matrix and train the regressor to forecast the time series – MaxBenChrist – 2016-12-27T21:43:02.330

tsfresh itself does not contain any estimator. You have to use sklearn, tensorflow or something similar for that. – MaxBenChrist – 2016-12-27T21:43:48.430

@MaxBenChrist - could you elaborate on what is meant by "shift the feature matrix and train the regressor to forecast the time series" ? I currently have a feature matrix but not sure how to convert this into predictive modelling. – joel.wilson – 2018-08-28T12:23:22.137

Answers

1

TSFRESH is already supporting Time Series Forecast.

See details and example here and here

SpanishBoy

Posted 2016-11-12T14:35:25.700

Reputation: 517

I have the same question and not able to understand how to use the tsfresh on predictive modelling. The example on the google stock has "id" column which I do not have. I get is a 5 * 784 matrix(due to 5 features) and completly lost the time factor from the output data. How to leverage the time series facility? Any example? – joel.wilson – 2018-08-28T12:27:59.333

Yes, I had an example ... If you can post more exactly the input-structure, I will try to adapt the example – SpanishBoy – 2018-09-10T13:45:31.323

I got this problem aswell, the notebook seems not to be up to date anymore. Does anyone have a tsfresh solution which works? – iLuvCode – 2020-05-14T13:51:33.343