Skip to main content

python package for generating calendars for machine learning timeseries analysis.

Project description

lilio: Calendar generator for machine learning with timeseries data

Logo

github repo badge github license badge rsd badge DOI fair-software badge Documentation Status build sonarcloud workflow scc badge

A python package for generating calendars to resample timeseries into training and target data for machine learning. Named after the inventor of the Gregorian Calendar.

Lilio was originally designed for use in s2spy, a high-level python package integrating expert knowledge and artificial intelligence to boost (sub) seasonal forecasting.

Installation

workflow pypi badge supported python versions

To install the latest release of lilio, do:

python3 -m pip install lilio

To install the in-development version from the GitHub repository, do:

python3 -m pip install git+https://github.com/AI4S2S/lilio.git

Configure the package for development and testing

A more extensive developer guide can be found here.

The testing framework used here is pytest. Before running the test, we get a local copy of the source code and install lilio via the command:

git clone https://github.com/AI4S2S/lilio.git
cd lilio
python3 -m pip install -e .[dev]

Then, run tests:

hatch run test

How the lilio calendars work

In Lilio, calendars are 2-dimensional. Each row (year) represents a unique observation, whereas each column corresponds to a precursor period with a certain lag. This is how we like to structure our data for ML applications.

Conceptual illustration of Lilio Calendar

We define the "anchor date" to be between the target and precursor periods (strictly speaking, it is the start of the first target interval). All other intervals are expressed as offsets to this anchor date. Conveniently, this eliminates any ambiguity related to leap years.

Here's a calendar generated with Lilio:

>>> calendar = lilio.daily_calendar(anchor="11-30", length='180d')
>>> calendar = calendar.map_years(2020, 2021)
>>> calendar.show()
i_interval                         -1                         1
anchor_year
2021         [2021-06-03, 2021-11-30)  [2021-11-30, 2022-05-29)
2020         [2020-06-03, 2020-11-30)  [2020-11-30, 2021-05-29)

Now, the user can load the data input_data (e.g. pandas DataFrame) and resample it to the desired timescales configured in the calendar:

>>> calendar = calendar.map_to_data(input_data)
>>> bins = lilio.resample(calendar, input_data)
>>> bins
  anchor_year  i_interval                  interval  mean_data  target
0        2020          -1  [2020-06-03, 2020-11-30)      275.5    True
1        2020           1  [2020-11-30, 2021-05-29)       95.5   False
2        2021          -1  [2021-06-03, 2021-11-30)      640.5    True
3        2021           1  [2021-11-30, 2022-05-29)      460.5   False

For convenience, Lilio offers a few shorthands for standard of calendars e.g. monthly_calendar and weekly_calendar. However, you can also create custom calendars by calling Calendar directly. For a nice walkthrough, see this example notebook.

Documentation

Documentation Status

For detailed information on using lilio package, visit the documentation page hosted at Readthedocs.

Contributing

If you want to contribute to the development of lilio, have a look at the contribution guidelines.

Credits

This package was created with Cookiecutter and the NLeSC/python-template.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lilio-0.3.1.tar.gz (1.3 MB view details)

Uploaded Source

Built Distribution

lilio-0.3.1-py3-none-any.whl (33.0 kB view details)

Uploaded Python 3

File details

Details for the file lilio-0.3.1.tar.gz.

File metadata

  • Download URL: lilio-0.3.1.tar.gz
  • Upload date:
  • Size: 1.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for lilio-0.3.1.tar.gz
Algorithm Hash digest
SHA256 398e04658aa1df1936054af296afcf50d7b1c8bee18d11333e9fe0545b1526e8
MD5 4d312d3e9eb5f0438808c89d44447b3f
BLAKE2b-256 9c65d29503ac95f2c26a351a50b573a0968d0f013f08c5783438842eead53f9d

See more details on using hashes here.

File details

Details for the file lilio-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: lilio-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 33.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for lilio-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3d02a77b42f9047b7383045c560b80dca8e76adb878b0b9f7f39ddb0ca9b9eaf
MD5 026d2e5c2bbb8d7da540fdd5d6d924aa
BLAKE2b-256 9606bd173c8c4dd0eef6393e7d19f532e01666827ba26da7737344e236fbbc96

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page