from spotforecast2.multitask import LazyTask
task = LazyTask(data_frame_name="demo10", predict_size=24)
print(f"Task: {task.TASK}")
print(f"Predict size: {task.config.predict_size}")Task: lazy
Predict size: 24
multitask.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 OptunaTask or SpotOptimTask), they are loaded and applied automatically so that the lazy task benefits from prior tuning without re-running the search.
| Name | Description |
|---|---|
| run | Run lazy fitting for all targets. |
Run lazy fitting for all targets.
| Name | Type | Description | Default |
|---|---|---|---|
| show | bool | If True, display prediction figures. |
True |
| 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 |
| Name | Type | Description |
|---|---|---|
| Dict[str, Any] | Aggregated prediction package. Per-target packages are stored | |
| Dict[str, Any] | on self.results["lazy"]. |
import tempfile
import numpy as np
import pandas as pd
from lightgbm import LGBMRegressor
from spotforecast2.multitask import LazyTask
from spotforecast2_safe.configurator.config_multi import ConfigMulti
from spotforecast2_safe.forecaster.recursive import ForecasterRecursive
from spotforecast2_safe.preprocessing import RollingFeatures
rng = np.random.default_rng(0)
n = 24 * 14 # two weeks of hourly data
idx = pd.date_range("2023-01-01", periods=n, freq="h", tz="UTC")
idx.name = "DateTime"
df = pd.DataFrame({"load": rng.normal(100, 10, n)}, index=idx)
def _fast_factory(config, *, weight_func=None, target=None):
return ForecasterRecursive(
estimator=LGBMRegressor(
n_estimators=10,
random_state=config.random_state,
verbose=-1,
),
lags=6,
window_features=RollingFeatures(stats=["mean"], window_sizes=6),
weight_func=weight_func,
)
with tempfile.TemporaryDirectory() as tmp:
cfg = ConfigMulti(
predict_size=6,
use_exogenous_features=False,
use_outlier_detection=False,
auto_save_models=False,
number_folds=2,
random_state=42,
forecaster_factory=_fast_factory,
cache_home=tmp,
)
task = LazyTask(cfg, dataframe=df)
task.prepare_data().detect_outliers().impute().build_exogenous_features()
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_3070/264861878.py:40: 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().detect_outliers().impute().build_exogenous_features()
Future predictions: 6 steps