Custom Window, Selection, and Forecasting#

Back to custom extensions

Use these hooks when the timing, parameter search, or forecast-combination logic is project-specific.

custom_stage_policy#

mf.window.custom_stage_policy(selector, *, name=None, metadata=None) -> mf.window.StagePolicy

Selector Contract#

selector(index: pandas.Index, *, item: dict, policy: StagePolicy)

The selector may return a boolean mask, a slice, integer positions, or index labels. The result must select at least one label and must not select dates outside the supplied index.

Example#

def last_fit_half(index, *, item, policy):
    fit_idx = item["fit_idx"]
    return index[fit_idx[len(fit_idx) // 2 :]]

policy = mf.window.custom_stage_policy(last_fit_half)

Use this for non-standard model-selection or preprocessing samples. Standard expanding, rolling, fixed-reference, and origin-available behavior should use mf.window.stage_policy(...).

custom_combination#

mf.forecasting.custom_combination(
    name,
    func,
    *,
    models=None,
    **params,
) -> mf.forecasting.CombinationSpec

Combination Callable Contract#

func(forecasts: pandas.DataFrame, *, actual: pandas.Series, **params)

forecasts is a wide matrix of base-model predictions indexed by (date, origin, origin_pos, horizon). The output must be a Series or one-dimensional array-like object aligned to those rows.

Example#

def blend(forecasts, *, actual, weight=0.5):
    return weight * forecasts.iloc[:, 0] + (1.0 - weight) * forecasts.iloc[:, -1]

combination = mf.forecasting.custom_combination(
    "ridge_lasso_blend",
    blend,
    models=["ridge", "lasso"],
    weight=0.25,
)

Boundary#

Hook

Owns

Does not own

custom_stage_policy

sample labels for one stage

fitting or scoring

custom_search

hyperparameter search algorithm

model default search spaces

custom_combination

combining already produced forecasts

fit-time model ensembles