Back to models
Param Estimator

FunctionParamFitter

Constructs a parameter fitter from an arbitrary callable.

Quickstart

python
from sktime.param_est.compose import FunctionParamFitter

estimator = FunctionParamFitter(param, func, kw_args=None, X_type=None)

Parameters(4)

paramstr
The name of the parameter to set.
funccallable (X: X_type, ** kwargs) -> Any
The callable to use for the parameter estimation. This will be passed the same arguments as estimator, with args and kwargs forwarded.
kw_argsdict, default=None
Dictionary of additional keyword arguments to pass to func.
X_typestr, one of “pd.DataFrame, pd.Series, np.ndarray”, or list thereof

default = [“pd.DataFrame”, “pd.Series”, “np.ndarray”] list of types that func is assumed to allow for X (see signature above) if X passed to transform/inverse_transform is not on the list,

it will be converted to the first list element before passed to funcs

Examples

This class could be used to construct a parameter estimator that selects a forecaster based on the input data’s length. The selected forecaster can be stored in the selected_forecaster_ attribute, which can be then passed down to a MultiplexForecaster via a PluginParamsForecaster.
>>> import numpy as np
>>> from sktime.param_est.compose import FunctionParamFitter
>>> param_est = FunctionParamFitter (
... param = "selected_forecaster",
... func = (
... lambda X, threshold: "naive-seasonal"
... if len (X) >= threshold
... else "naive-last"
... ),
... kw_args = { "threshold": 7 },
... )
>>> param_est. fit (np. asarray ([1, 2, 3, 4 ])) FunctionParamFitter(
... )
>>> param_est. get_fitted_params () {'selected_forecaster': 'naive-last'}
>>> param_est. fit (np. asarray ([1, 2, 3, 4, 5, 6, 7 ])) FunctionParamFitter(
... )
>>> param_est. get_fitted_params () {'selected_forecaster': 'naive-seasonal'} The full conditional forecaster selection pipeline could look like this:
>>> from sktime.forecasting.compose import MultiplexForecaster
>>> from sktime.forecasting.naive import NaiveForecaster
>>> from sktime.param_est.plugin import PluginParamsForecaster
>>> forecaster = PluginParamsForecaster (
... param_est = param_est,
... forecaster = MultiplexForecaster (
... forecasters = [
... ("naive-last", NaiveForecaster ()),
... ("naive-seasonal", NaiveForecaster (sp = 7)),
... ]
... ),
... )
>>> forecaster. fit (np. asarray ([1, 2, 3, 4 ])) PluginParamsForecaster(
... )
>>> forecaster. predict (fh = [1, 2, 3 ]) array([[4.], [4.], [4.]])
>>> forecaster. fit (np. asarray ([1, 2, 3, 4, 5, 6, 7 ])) PluginParamsForecaster(
... )
>>> forecaster. predict (fh = [1, 2, 3 ]) array([[1.], [2.], [3.]])