Skip to content

check_search_interval_predict_delegates

yohou.testing.check_search_interval_predict_delegates(search_cv, X_future=None, X_forecast=None)

Check predict_interval() works after interval search with refit.

Validates that the best forecaster supports predict_interval and returns a valid interval prediction DataFrame.

Parameters

Name Type Description Default
search_cv BaseSearchCV

Fitted search CV instance (interval scorer, refit=True).

required
X_future DataFrame

Known-future features forwarded to predict_interval().

None
X_forecast DataFrame

External forecast features forwarded to predict_interval().

None

Raises

Type Description
AssertionError

If predict_interval() fails or returns invalid predictions.

Source Code

Source code in src/yohou/testing/search.py
def check_search_interval_predict_delegates(
    search_cv,
    X_future: pl.DataFrame | None = None,
    X_forecast: pl.DataFrame | None = None,
) -> None:
    """Check predict_interval() works after interval search with refit.

    Validates that the best forecaster supports ``predict_interval`` and
    returns a valid interval prediction DataFrame.

    Parameters
    ----------
    search_cv : BaseSearchCV
        Fitted search CV instance (interval scorer, refit=True).
    X_future : pl.DataFrame, optional
        Known-future features forwarded to predict_interval().
    X_forecast : pl.DataFrame, optional
        External forecast features forwarded to predict_interval().

    Raises
    ------
    AssertionError
        If predict_interval() fails or returns invalid predictions.

    """
    check_is_fitted(search_cv)

    coverage_rates = [0.9]

    y_pred = search_cv.predict_interval(coverage_rates=coverage_rates, X_future=X_future, X_forecast=X_forecast)

    assert isinstance(y_pred, pl.DataFrame), f"predict_interval should return pl.DataFrame, got {type(y_pred)}"
    assert "vintage_time" in y_pred.columns, "Interval predictions should have 'vintage_time' column"
    assert "time" in y_pred.columns, "Interval predictions should have 'time' column"

    interval_cols = [c for c in y_pred.columns if "_lower_" in c or "_upper_" in c]
    assert len(interval_cols) > 0, f"Interval predictions should have _lower_/_upper_ columns, got {y_pred.columns}"