multitask.lazy.LazyTask

multitask.lazy.LazyTask(
    config=None,
    *,
    dataframe=None,
    data_test=None,
    cache_home=None,
    log_level=logging.INFO,
    **overrides,
)

Task 1 — Lazy Fitting with default LightGBM parameters.

Creates an unfitted forecaster per target and fits with default hyperparameters. No cross-validation or tuning is performed.

When cached tuning results are available (saved by a prior run in the spotforecast2 sibling package), they are loaded and applied automatically so that the lazy task benefits from prior tuning without re-running the search.

Examples

import tempfile
from pathlib import Path
from spotforecast2_safe.multitask import LazyTask
from spotforecast2_safe.configurator.config_multi import ConfigMulti

with tempfile.TemporaryDirectory() as tmp:
    cfg = ConfigMulti(data_frame_name="demo10", predict_size=24, cache_home=Path(tmp))
    task = LazyTask(cfg)
    print(f"Task: {task.TASK}")
    print(f"Predict size: {task.config.predict_size}")
Task: lazy
Predict size: 24

Methods

Name Description
run Run lazy fitting for all targets.

run

multitask.lazy.LazyTask.run(
    show=False,
    use_tuned_params=True,
    max_age_days=None,
    **kwargs,
)

Run lazy fitting for all targets.

Parameters

Name Type Description Default
show bool If True, invoke the visualisation hooks. False
use_tuned_params bool If True, load and apply cached tuning results for each target. True
max_age_days Optional[float] Maximum age in days for cached tuning results. None accepts any age. None

Returns

Name Type Description
Dict[str, Any] Aggregated prediction package. Per-target packages are stored
Dict[str, Any] on self.results["lazy"].

Examples

import tempfile
import pandas as pd
import numpy as np
from spotforecast2_safe.multitask.lazy import LazyTask
from spotforecast2_safe.configurator.config_multi import ConfigMulti

rng = np.random.default_rng(0)
idx = pd.date_range("2023-01-01", periods=24 * 14, freq="h", tz="UTC")
df = pd.DataFrame({"load": rng.normal(100, 10, len(idx))}, index=idx)
df.index.name = "DateTime"

with tempfile.TemporaryDirectory() as tmp:
    cfg = ConfigMulti(
        predict_size=6,
        use_exogenous_features=False,
        use_outlier_detection=False,
        cache_home=tmp,
        auto_save_models=False,
        number_folds=2,
    )
    task = LazyTask(cfg, dataframe=df)
    task.prepare_data()
    result = task.run(show=False, use_tuned_params=False)
    print(f"Future predictions: {len(result['future_pred'])} steps")
    assert len(result["future_pred"]) == 6
/tmp/ipykernel_5540/2078337976.py:22: DeprecationWarning: Derived pipeline fields (start_download, end_download, data_start, data_end, cov_start, cov_end, end_train_ts, start_train_ts) have moved to task.run_state. Reading them from the config is deprecated and will stop working in the next major release. config.targets continues to hold the user input unchanged; read the resolved list from task.run_state.targets.
  task.prepare_data()
Future predictions: 6 steps