Note
Go to the end to download the full example code
Timedelta-based schedule
and after
arguments.#
By default, passing TimedeltaTypes
as both the schedule
and the after
argument
causes the folds to align to the right edge of the available
data.
from rics import configure_stuff
from rics.ml.time_split import log_split_progress, plot, settings, split
configure_stuff(datefmt="")
data = ("2022-02", "2022-03")
config = dict(schedule="7d", before="3d", after="5d", available=data)
plot(**config, bar_labels=False)
for fold in log_split_progress(split(**config), logger="my-logger"):
print("Doing work..")
👻 Configured some stuff just the way I like it!
[my-logger:INFO] Begin fold 1/3: '2022-02-07' <= [schedule: '2022-02-10' (Thursday)] < '2022-02-15'.
Doing work..
[my-logger:INFO] Finished fold 1/3: [schedule: '2022-02-10' (Thursday)] after 46μs.
[my-logger:INFO] Begin fold 2/3: '2022-02-14' <= [schedule: '2022-02-17' (Thursday)] < '2022-02-22'.
Doing work..
[my-logger:INFO] Finished fold 2/3: [schedule: '2022-02-17' (Thursday)] after 44μs.
[my-logger:INFO] Begin fold 3/3: '2022-02-21' <= [schedule: '2022-02-24' (Thursday)] < '2022-03-01'.
Doing work..
[my-logger:INFO] Finished fold 3/3: [schedule: '2022-02-24' (Thursday)] after 42μs.
Setting settings.misc.snap_to_end
to False
will adopt the
default behavior used by pandas.date_range()
.
settings.misc.snap_to_end = False
plot(**config, bar_labels=False)
for fold in log_split_progress(split(**config), logger="my-logger"):
print("Doing work..")
[my-logger:INFO] Begin fold 1/3: '2022-02-05' <= [schedule: '2022-02-08' (Tuesday)] < '2022-02-13'.
Doing work..
[my-logger:INFO] Finished fold 1/3: [schedule: '2022-02-08' (Tuesday)] after 46μs.
[my-logger:INFO] Begin fold 2/3: '2022-02-12' <= [schedule: '2022-02-15' (Tuesday)] < '2022-02-20'.
Doing work..
[my-logger:INFO] Finished fold 2/3: [schedule: '2022-02-15' (Tuesday)] after 44μs.
[my-logger:INFO] Begin fold 3/3: '2022-02-19' <= [schedule: '2022-02-22' (Tuesday)] < '2022-02-27'.
Doing work..
[my-logger:INFO] Finished fold 3/3: [schedule: '2022-02-22' (Tuesday)] after 43μs.
The configuration in rics.ml.time_split.settings
are global, so changes made will remain in effect for all
callers until the original value is reset.
settings.misc.snap_to_end = True
Total running time of the script: (0 minutes 0.562 seconds)