Calendar shorthands
While Lilio’s Calendar
allows you to fully customize a calendar to your specific use-case, sometimes a quick way to create a calendar is nice. To this end, we have included some calendar “shorthands”, to quickly generate calendars with basic parameters.
These are the following: - daily_calendar
- weekly_calendar
- monthly_calendar
Let’s start with the daily_calendar
. This calendar revolves around defining the anchor as a certain date (e.g. 25 December), and lengths as a number of days.
In the following example, we count down to Christmas, with seven precursor periods preceding the target:
[1]:
import lilio
lilio.daily_calendar(
anchor="12-25",
length="1d",
n_precursors=7, # Number of precursor periods
)
[1]:
Calendar(
anchor='12-25',
allow_overlap=False,
mapping=None,
intervals=[
Interval(role='target', length='1d', gap='0d'),
Interval(role='precursor', length='1d', gap='0d'),
Interval(role='precursor', length='1d', gap='0d'),
Interval(role='precursor', length='1d', gap='0d'),
Interval(role='precursor', length='1d', gap='0d'),
Interval(role='precursor', length='1d', gap='0d'),
Interval(role='precursor', length='1d', gap='0d'),
Interval(role='precursor', length='1d', gap='0d')
]
)
The weekly calendar revolves around calendar weeks. This means that you need to specify a week number (and optionally a weekday) as anchor.
Note that if no n_precursors
is specified, the calendar tries to fill a year. In this case that means six 8-week periods:
[2]:
cal = lilio.weekly_calendar(
anchor="W40-4",
length="8W",
)
cal.map_years(2020, 2020)
cal.show()
[2]:
i_interval | -5 | -4 | -3 | -2 | -1 | 1 |
---|---|---|---|---|---|---|
anchor_year | ||||||
2020 | [2020-01-02, 2020-02-27) | [2020-02-27, 2020-04-23) | [2020-04-23, 2020-06-18) | [2020-06-18, 2020-08-13) | [2020-08-13, 2020-10-08) | [2020-10-08, 2020-12-03) |
Lastly there is the monthly_calendar
. This is the same as the previous calendars, except it revolves around months.
Here we can also demonstrate what happens when we want more precursors than what would fit in a year:
[3]:
cal = lilio.monthly_calendar(
anchor="Dec",
length='4M',
n_targets=2,
n_precursors=2,
)
cal.map_years(2018, 2020)
cal.show()
[3]:
i_interval | -2 | -1 | 1 | 2 |
---|---|---|---|---|
anchor_year | ||||
2020 | [2020-04-01, 2020-08-01) | [2020-08-01, 2020-12-01) | [2020-12-01, 2021-04-01) | [2021-04-01, 2021-08-01) |
2018 | [2018-04-01, 2018-08-01) | [2018-08-01, 2018-12-01) | [2018-12-01, 2019-04-01) | [2019-04-01, 2019-08-01) |
The calendar will have the specified number of periods, but skips an anchor year to avoid overlapping intervals.
If you do want overlapping intervals (and take care of the possibility of train-test leakage), set allow_overlap
to True
:
[4]:
cal = lilio.monthly_calendar(
anchor="Dec",
length='4M',
n_targets=2,
n_precursors=2,
allow_overlap=True,
)
cal.map_years(2018, 2020)
cal.show()
[4]:
i_interval | -2 | -1 | 1 | 2 |
---|---|---|---|---|
anchor_year | ||||
2020 | [2020-04-01, 2020-08-01) | [2020-08-01, 2020-12-01) | [2020-12-01, 2021-04-01) | [2021-04-01, 2021-08-01) |
2019 | [2019-04-01, 2019-08-01) | [2019-08-01, 2019-12-01) | [2019-12-01, 2020-04-01) | [2020-04-01, 2020-08-01) |
2018 | [2018-04-01, 2018-08-01) | [2018-08-01, 2018-12-01) | [2018-12-01, 2019-04-01) | [2019-04-01, 2019-08-01) |
[ ]: