Basic functions to read timeseries files like `.arff` and `.ts` files.
from nbdev.showdoc import *
from fastai2.data.external import *
# #export
# from zipfile import ZipFile
Plot Timeseries¶
path_data = Config().data
path_data
file_extract_at_filename
is used by default in unzip_data
to decompress the downloaded file in a folder that has the same name as the zip filename.
unzip_data
download and decompress the downloaded file in a folder and decompress it in a folder that has the same name as the zip filename
dsname = 'NATOPS' #'NATOPS', 'LSST', 'Wine', 'Epilepsy', 'HandMovementDirection'
path = unzip_data(URLs_TS.NATOPS)
path
path.ls()
fname_train = f'{dsname}_TRAIN.arff'
fname_test = f'{dsname}_TEST.arff'
fnames = [path/fname_train, path/fname_test]
fnames
data = TSData.from_arff(fnames)
data
print(data)
data.dsname, data.fnames, data.n_channels, data.sizes, data.x.shape, data.y.shape
test_eq(data.dsname, ['NATOPS_TRAIN', 'NATOPS_TEST'])
test_eq(data.n_channels, 24)
test_eq(data.sizes, ((360, 24, 51), (360,)))
test_eq(data.x.shape, (360, 24, 51))
test_eq(data.y.shape, (360,))
type(data.get_items()[1][0]), data.get_items()[1][0]
type(data.get_y()[1]), data.get_y()[1]
test_eq(data.get_y()[1], '3.0')
idx = 4
ts, title = data.get_items()[idx]
show_timeseries(ts, title=title)
# show_timeseries(ts, title=title, chs=range(0,24,3))
fname_train = path_data/f'{dsname}/{dsname}_TRAIN.ts'
fname_train
train_x_ts, train_y_ts = load_from_tsfile_to_array(fname_train)
train_x_ts.shape, train_y_ts.shape
train_x_ts[1].shape
train_x_ts[10][0][30]
{% include image.html alt="" file="https://github.com/ai-fast-track/timeseries/blob/master/images/blue-sea.jpg?raw=1" %}