Fit the forecaster using the recorded best hyperparameters.
After tuning (or manually setting best_params and best_lags), this method loads the data, sets the optimal parameters/lags, and fits the forecaster on the full training + dev set up to end_dev.
Create a model instance with defaults drawn from a config object.
Extracts every __init__ parameter that exists as a config attribute, translating the two known name mismatches (API_COUNTRY_CODE → country_code, end_train_default → end_dev). Caller-supplied overrides take precedence over config values.
Dict[str, Any]: A result package containing actual values, predictions, and calculated metrics (MAE, MAPE).
Examples
import osimport shutilimport tempfilefrom pathlib import Pathimport pandas as pdfrom lightgbm import LGBMRegressorfrom spotforecast2_safe.data.fetch_data import get_package_data_homefrom spotforecast2_safe.forecaster.recursive import ForecasterRecursivefrom spotforecast2_safe.forecaster.wrappers import ForecasterRecursiveLGBM# Setup temporary data environmenttmp_dir = tempfile.mkdtemp()os.environ["SPOTFORECAST2_DATA"] = tmp_dirdata_path = Path(tmp_dir) /"interim"data_path.mkdir(parents=True)# Load demo data and rename columns to match expectationsdemo_path = get_package_data_home() /"demo01.csv"df = pd.read_csv(demo_path)df = df.rename(columns={"Time": "Time (UTC)","Actual": "Actual Load","Forecast": "Forecasted Load",})df.to_csv(data_path /"energy_load.csv", index=False)# Initialize model — override forecaster for small demo datamodel = ForecasterRecursiveLGBM(iteration=0, end_dev="2022-01-05 00:00+00:00")model.forecaster = ForecasterRecursive( estimator=LGBMRegressor(n_jobs=-1, verbose=-1, random_state=123456789), lags=12,)result = model.package_prediction(predict_size=24)print("train_actual"in result and"future_pred"in result)# Cleanupshutil.rmtree(tmp_dir)del os.environ["SPOTFORECAST2_DATA"]
╭─────────────────────────────── IgnoredArgumentWarning ───────────────────────────────╮│ The number of bins has been reduced from 10 to 6 due to duplicated edges caused by ││ repeated predicted values.\n\nCategory : ││ spotforecast2.exceptions.IgnoredArgumentWarning\nLocation : ││ /home/runner/work/spotforecast2-safe/spotforecast2-safe/src/spotforecast2_safe/prepr ││ ocessing/_binner.py:233\nSuppress : warnings.simplefilter('ignore', ││ category=IgnoredArgumentWarning) │╰──────────────────────────────────────────────────────────────────────────────────────╯
Directory for the model file. If None, defaults to get_cache_home().
None
Examples
import osimport tempfilefrom spotforecast2_safe.forecaster.wrappers import ForecasterRecursiveModelmodel = ForecasterRecursiveModel(iteration=0, name="test")with tempfile.TemporaryDirectory() as tmpdir: model.save_to_file(model_dir=tmpdir)print(any("test_forecaster_0"in f for f in os.listdir(tmpdir)))
Wrapper-level keys (iteration, name, predict_size, …) are set directly on the model. Keys prefixed with forecaster__ are forwarded to ForecasterRecursive.set_params().
Additional parameter names mapped to their new values. Parameters can target the wrapper (e.g. name="new"), the forecaster (e.g. forecaster__lags=5), or the estimator inside the forecaster (e.g. forecaster__estimator__fit_intercept=False).
In spotforecast2-safe this is a simulated stub that marks the model as tuned without performing an actual Bayesian search. A full implementation using bayesian_search_forecaster will be provided in the spotforecast2 package.
#TODO: Implement real Bayesian search in spotforecast2