-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtsfresh_features.py
34 lines (21 loc) · 1.01 KB
/
tsfresh_features.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import pandas as pd
import h5py
import numpy as np
from tsfresh import extract_features
from tsfresh.feature_extraction.settings import MinimalFCParameters
import h5py
import os
if __name__ == "__main__":
savefile = "tsfresh_features.h5"
datafile = "simSeriesData.h5"
chunckLength = 100
with h5py.File(datafile,"r") as f:
n = f["deltas"].shape[0]//chunckLength
for i in range(n):
print(f"Chunck: {i}")
ts = np.tile(f["t"],chunckLength)
deltas = np.reshape(f["deltas"][i*chunckLength:(i+1)*chunckLength],(-1,))
ids = np.repeat(range(i*chunckLength,(i+1)*chunckLength),f["deltas"].shape[1])
data = pd.DataFrame({'id':ids,'time':ts,'y':deltas})
features = extract_features(data,column_id="id", column_sort="time", default_fc_parameters=MinimalFCParameters(),n_jobs=15)
features.to_hdf(savefile, 'table', mode='a',complevel=9, complib='zlib',format='table',append=True)