multitask.lazy.execute_lazy

multitask.lazy.execute_lazy(
    task,
    show=False,
    use_tuned_params=True,
    max_age_days=None,
)

Execute lazy fitting for all targets on task.

Thin wrapper around BaseTask._run_strategy using LazyStrategy. When use_tuned_params is True (the default), previously saved tuning results are loaded from cache and applied to the forecaster. If no cached results are found the forecaster uses default parameters.

Parameters

Name Type Description Default
task BaseTask A BaseTask (or subclass) instance with prepared data. required
show bool If True, invoke the visualisation hooks. False
use_tuned_params bool If True, attempt to load cached tuning results (best parameters and lags) 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 (weighted combination of all targets).
Dict[str, Any] Per-target packages are stored on task.results["lazy"].
Dict[str, Any] When task.config.auto_save_models is True (the default), fitted
Dict[str, Any] models are saved to disk so PredictTask can load them directly.

Examples

import tempfile
import pandas as pd
import numpy as np
from spotforecast2_safe.multitask.lazy import LazyTask, execute_lazy
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 = execute_lazy(task, show=False, use_tuned_params=False)
    print(f"Keys: {list(result.keys())[:4]}")
    print(f"Forecast horizon: {len(result['future_pred'])} steps")
    assert len(result["future_pred"]) == 6
Keys: ['train_actual', 'train_pred', 'future_actual', 'future_pred']
Forecast horizon: 6 steps