Skip to main content

Tabular Time Series

Summary

This repo was created as I did not find a function able to transform a time-series (1D) into a tabular format (X, y).

Usage

TimeSeriesGenerator

The docstring is as follows. Given a 1D array data = [0, 1, 2, 3, 4, 5, 6], generates X, y following the parameters p(autoregressive), s (seasonal) and n (lenght of y).

Therefore, it makes it possible to train a neural network (e.g.) that 2 autoregressive entries (e.g. p = 2) and predicts the next two (n = 2) using 2 (n = 2) entries with lag 4 (s = 4).

>> data = [0, 1, 2, 3, 4, 5, 6]
>> p, n = 2, 2
>> ts = TimeSeriesGenerator(data, p, n)
>> for _, X, y in ts:
...    print(X, y)
    [0, 1] [2, 3]
    [1, 2] [3, 4]
    [2, 3] [4, 5]
    [3, 4] [5, 6]
>> p, n, s = 2, 2, 4
>> ts = TimeSeriesGenerator(data, p, n, s)
>> for X, y in ts:
...    # both y have their respective seasonal entry
...    print(data.index(y[0]) - data.index(X[0]) == s, data.index(y[1]) - data.index(X[1]) == s)
...    print(X, y)
    [0, 1], [2, 3] [4, 5]
    [1, 2], [3, 4] [5, 6]

TimeSeriesGeneratorOnline

To support online learning (and streaming) applications, TimeSeriesGeneratorOnline enables applications to give real time measurements and returns a bool b stating if it was possible to generate features, considering the given seasonal s, autoregressive ar and output y.

>>> from tabular_time_series.tsgeneratoronline import TimeSeriesGeneratorOnline
>>> data = [i for i in range(10)]
>>> p, n, s = 2, 2, 4
>>> tsgo = TimeSeriesGeneratorOnline(p, n, s)
>>> for X in data:
...     b, (s, ar, y) = tsgo(X)
...     print(X, '|', b, s, ar, y)
...
0 | False None None None
1 | False None None None
2 | False None None None
3 | False None None None
4 | False None None None
5 | False None None None
6 | True [0, 1] [2, 3] [4, 5]
7 | True [1, 2] [3, 4] [5, 6]
8 | True [2, 3] [4, 5] [6, 7]
9 | True [3, 4] [5, 6] [7, 8]

timeseries2df

Considering that many times a batch array is needed for training, timeseries2df can be used to generate a pandas DataFrame that will contain columns in the format:

>>> from tabular_time_series.tsdf import timeseries2df
>>> data = list(range(10))
>>> p, n, s = 2, 2, 4
>>> df = timeseries2df(data, p, n, s)
>>> df
   y(ts4)_1  y(ts4)_2  y(t-1)  y(t-0)  y(t+1)  y(t+2)
0         0         1       2       3       4       5
1         1         2       3       4       5       6
2         2         3       4       5       6       7
3         3         4       5       6       7       8
4         4         5       6       7       8       9

Release files for tabular-time-series 1.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tabular-time-series 1.1.3
File Size Uploaded
tabular-time-series-1.1.3.tar.gz 4.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tabular-time-series 1.1.3
File Interpreter ABI Platform
tabular_time_series-1.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 10.1 kB

Release files / tabular-time-series-1.1.3.tar.gz

Download URL tabular-time-series-1.1.3.tar.gz
Size 4.7 kB
Tags Source
SHA-256 checksum
How to use checksums
9fbfce82f9cf6489d8094f178df2ed3f66b1a94235ac83dffd0d40f7df5af0df
BLAKE2b-256 checksum
How to use checksums
23aca447291fd6b43191380757f1e2ca1e9e818c0f7d3c907729e8a76f9d9818
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.8 CPython/3.8.2 Linux/5.8.0-1040-azure

Release files / tabular_time_series-1.1.3-py3-none-any.whl

Download URL tabular_time_series-1.1.3-py3-none-any.whl
Size 5.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4eadb8e841c80269e0e3b8f0fc3d54f5f0e7644d99278829fad955433ebd4209
BLAKE2b-256 checksum
How to use checksums
3475b500242da1687903517ba7de8db275364cb821d32d7d39d046ff4b03fd53
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.8 CPython/3.8.2 Linux/5.8.0-1040-azure

Release history Release notifications | RSS feed

This release

1.1.3 This release

2 release files

1.1.2

2 release files

1.1.0

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.2.32

2 release files

0.2.31

2 release files

0.2.21

2 release files

0.2.3

2 release files

0.2.1

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page