How to Forecast Through MLflow's Generic Predict Interface¶
This guide shows you how to forecast with a yohou model loaded through
mlflow.pyfunc.load_model. Use it when your code loads MLflow models generically
rather than through yohou_mlflow.load_model.
Prerequisites¶
- A forecaster saved or logged with yohou-mlflow
- New observations as polars DataFrames, if you want to forecast from them
Steps¶
1. Load the model¶
Load only models you trust this way: MLflow imports the modules the model file names
before any check runs. For a model you have not reviewed, run
check_compatibility first, or use
yohou_mlflow.load_model.
If the forecaster contains your own estimator classes, pass them at load time:
mlflow.pyfunc.load_model(uri, model_config={"extra_trusted_types": [...]}).
2. Forecast¶
To forecast from the saved state, pass an empty dict:
To forecast from new observations, pass them under y. The model observes them and
forecasts once, from the last observed time:
Pass exogenous features under X_actual, X_future and X_forecast, the names yohou
uses. X_actual is only accepted together with y:
3. Choose what to predict¶
Pass params to select the prediction and its options:
-
Prediction intervals:
-
Class probabilities, for a class-probability forecaster:
-
A different number of steps, or some panel groups only:
The result is a polars DataFrame, the same frame the yohou method returns.
4. Keep the update, if you need it¶
Each predict call works on a copy, so the observations are not kept. To keep them,
load the forecaster itself, observe, and register it again:
import yohou_mlflow
forecaster = yohou_mlflow.load_model("models:/daily-demand/latest")
forecaster.observe(new_rows)
with mlflow.start_run():
yohou_mlflow.log_model(forecaster, name="forecaster", registered_model_name="daily-demand")
Troubleshooting¶
- Problem:
TypeError: The yohou pyfunc input must be a dict of polars DataFrames - Pass a dict of polars frames. pandas input, and therefore
mlflow models serveand Spark UDFs, is not supported yet. - Problem:
prediction_type='interval' is not supported by this forecaster - The forecaster cannot produce that prediction. The error lists the types it supports.
See Also¶
- pyfunc contract: every input key, param and error
- Concepts: why each call works on a copy