multitask.run

multitask.run(
    config=None,
    *,
    task='lazy',
    dataframe=None,
    data_test=None,
    project_name='test_project',
    cache_home=None,
    plot_with_outliers=False,
    show=False,
    show_progress=False,
    dry_run=False,
    log_level=40,
    **overrides,
)

Run the MultiTask forecasting pipeline and return predictions.

Wraps the standard pipeline sequence into a single call. For the "clean" task only the cache directory is wiped and an empty DataFrame is returned. For all other tasks the full sequence

prepare_data -> detect_outliers -> impute ->
build_exogenous_features -> run

is executed and the aggregated future predictions are returned as a DataFrame.

Available tasks: "lazy", "defaults", "optuna", "spotoptim", "predict", "clean". The auto-tuning tasks "optuna" and "spotoptim" are available here (unlike in the spotforecast2-safe runner, which rejects them).

Parameters

Name Type Description Default
config Optional[PipelineConfig] A PipelineConfig-conforming object (typically ConfigMulti). When None, a fresh ConfigMulti() is constructed with default fields. Outlier bounds and aggregation agg_weights are domain-specific calibrations and must be supplied explicitly on ConfigMulti. None
task str Pipeline mode — one of "lazy", "defaults", "optuna", "spotoptim", "predict", or "clean". Defaults to "lazy". 'lazy'
dataframe Optional[pd.DataFrame] Input time-series data. Must contain a datetime column matching config.index_name and at least one numeric target column. Optional for "clean", required otherwise. None
data_test Optional[pd.DataFrame] Ground-truth DataFrame covering the prediction horizon. When supplied, populates test_actual and metrics_future in the prediction package. Optional. None
project_name str Active-dataset identifier. Sets config.data_frame_name, which drives cache-subdirectory and model-file naming. 'test_project'
cache_home Optional[str] Cache directory override. When None, the package default from get_cache_home() is used. None
plot_with_outliers bool Whether to render the optional outlier-visualisation step between detect_outliers and impute. Available in spotforecast2 (the figure is shown); the same flag raises NotImplementedError in spotforecast2-safe. False
show bool Whether to invoke the prediction display hooks after the task runs. False
show_progress bool Whether to print progress messages during pipeline execution. False
dry_run bool Forwarded to MultiTask; only meaningful for the "clean" task. False
log_level int Logging level. Defaults to 40 (ERROR). 40
**overrides Any Forwarded to config.set_params(**overrides) — a convenience for one-line tweaks (e.g. predict_size=24, n_trials_optuna=25) without building a fresh config. Unknown keys raise ValueError. Mutates the caller’s config object. {}

Returns

Name Type Description
pd.DataFrame DataFrame whose index is the forecast horizon timestamps and whose
pd.DataFrame single column "forecast" contains the aggregated predicted values.
pd.DataFrame For the "clean" task an empty DataFrame is returned.

Raises

Name Type Description
ValueError If task is not one of the supported task names, or if an unknown key is passed via **overrides.

Examples

Run the pipeline using cached or default model parameters ("lazy" task) and read the aggregated forecast off the returned DataFrame:

import tempfile
import warnings

warnings.filterwarnings("ignore")

from spotforecast2.multitask import run
from spotforecast2_safe.configurator.config_multi import ConfigMulti
from spotforecast2_safe.data.fetch_data import fetch_data, get_package_data_home

data_home = get_package_data_home()
df = fetch_data(filename=str(data_home / "demo10.csv")).iloc[:500]

config = ConfigMulti(
    predict_size=12,
    targets=["A"],
    lags_consider=[1, 2, 3],
    window_size=4,
    number_folds=2,
    use_exogenous_features=False,
    use_outlier_detection=False,
    auto_save_models=False,
    verbose=False,
)

forecast = run(
    config,
    task="lazy",
    dataframe=df,
    project_name="demo10_run",
    cache_home=tempfile.mkdtemp(),
)
print("columns:", list(forecast.columns))
print("rows:", len(forecast))
forecast.head()
WeightFunction: all sample weights for the requested index are zero (the window falls entirely within gap-penalty zones). Returning None so ForecasterRecursive uses uniform weighting.
columns: ['forecast']
rows: 12
forecast
2019-12-21 20:00:00+00:00 6396.025408
2019-12-21 21:00:00+00:00 2213.850600
2019-12-21 22:00:00+00:00 3561.499049
2019-12-21 23:00:00+00:00 -2798.778044
2019-12-22 00:00:00+00:00 -241.052416

Remove all cached models and artefacts for a project ("clean" task). Returns an empty DataFrame:

result = run(task="clean", project_name="demo10_run", cache_home=tempfile.mkdtemp())
print("empty:", result.empty)
[clean] Cache removed successfully: /tmp/tmpzsos_0k1
empty: True