manager.predictor.get_model_prediction

manager.predictor.get_model_prediction(
    model_name,
    model_dir=None,
    predict_size=None,
)

Get the prediction package from the latest trained model.

This function retrieves the latest iteration of a specified model from the cache and calls its package_prediction method to obtain a comprehensive set of predictions and metrics.

Parameters

Name Type Description Default
model_name str Name of the model to use (e.g., ‘lgbm’, ‘xgb’). required
model_dir Optional[Union[str, Path]] Directory where models are stored. If None, defaults to the library’s cache home. None
predict_size Optional[int] Optional override for the prediction horizon. None

Returns

Name Type Description
Dict[str, Any] A dictionary containing predictions and metrics produced by
Dict[str, Any] package_prediction().

Raises

Name Type Description
FileNotFoundError If no trained model is found for model_name in model_dir.
AttributeError If the loaded model does not implement a package_prediction method.
PredictionPackageError If package_prediction() itself fails — see forecaster.wrappers.model.ForecasterRecursiveModel.package_prediction.
OSError If the on-disk model file exists but cannot be deserialised (corrupt joblib).

Notes

predict_size is accepted by get_model_prediction() but only has effect if the concrete model’s package_prediction() accepts it. The original ForecasterRecursiveModel.package_prediction() does not — so this parameter is currently forward-looking API design, not yet wired end-to-end.

Examples

import tempfile
from spotforecast2_safe.manager.predictor import get_model_prediction

# When no model has been trained, get_model_prediction raises FileNotFoundError.
with tempfile.TemporaryDirectory() as tmpdir:
    try:
        get_model_prediction("lgbm", model_dir=tmpdir)
    except FileNotFoundError as e:
        print(type(e).__name__)
        assert "lgbm" in str(e)
FileNotFoundError