multitask.defaults.execute_defaults(task, show=False)
Execute defaults fitting for all targets on task.
Thin wrapper around BaseTask._run_strategy using DefaultsStrategy.
Parameters
| task |
BaseTask |
A BaseTask (or subclass) instance with prepared data. |
required |
| show |
bool |
If True, invoke the visualisation hooks. |
False |
Returns
|
Dict[str, Any] |
Aggregated prediction package (weighted combination of all targets, |
|
Dict[str, Any] |
or the single-target package when len(config.targets) == 1). |
|
Dict[str, Any] |
Per-target packages are stored on task.results["defaults"]. |
|
Dict[str, Any] |
When task.config.auto_save_models is True (the default), fitted |
|
Dict[str, Any] |
models are saved to disk so PredictTask(task_name="defaults") can |
|
Dict[str, Any] |
load them directly. |
Examples
import tempfile
import numpy as np
import pandas as pd
from pathlib import Path
from spotforecast2_safe.multitask.defaults import DefaultsTask, execute_defaults
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,
auto_save_models=False,
number_folds=2,
cache_home=Path(tmp),
verbose=False,
)
task = DefaultsTask(cfg, dataframe=df)
task.prepare_data().detect_outliers().impute().build_exogenous_features()
result = execute_defaults(task)
print(f"Future predictions: {len(result['future_pred'])} steps")
assert isinstance(result["future_pred"], pd.Series)
assert len(result["future_pred"]) == 6
Future predictions: 6 steps