Strategy interface for preparing a forecaster before the final fit.
Implementations return a forecaster with any tuning/parameter changes applied. The final forecaster.fit(...) and prediction packaging are performed by BaseTask._train_and_predict_target after this call.
Examples
import pandas as pdfrom spotforecast2_safe.multitask.strategies import ( TrainingStrategy, LazyStrategy, DefaultsStrategy,)# Both concrete strategies satisfy the TrainingStrategy protocol:# they expose a `name` attribute and a `prepare_forecaster` method.for cls in (LazyStrategy, DefaultsStrategy): s = cls()asserthasattr(s, "name"), f"{cls.__name__} missing .name"assertcallable(s.prepare_forecaster), f"{cls.__name__} missing .prepare_forecaster"print(f"{cls.__name__}.name = {s.name!r}")
import pandas as pdfrom sklearn.linear_model import LinearRegressionfrom spotforecast2_safe.forecaster.recursive import ForecasterRecursivefrom spotforecast2_safe.multitask.strategies import DefaultsStrategy# Demonstrate prepare_forecaster via a concrete implementation.# DefaultsStrategy is the simplest: it returns the forecaster unchanged.forecaster = ForecasterRecursive(estimator=LinearRegression(), lags=3)y_train = pd.Series(range(30), dtype=float, name="target_0")class _NullTask:passstrategy = DefaultsStrategy()result = strategy.prepare_forecaster(_NullTask(), "target_0", forecaster, y_train)assert result is forecasterprint(f"prepare_forecaster returned the same object: {result is forecaster}")