auxmodels

Supplemental models that build on scalecast’s functionality.

auto_arima()

scalecast.auxmodels.auto_arima(f: Forecaster, call_me: str = 'auto_arima', Xvars: Annotated[str, "must exist as a key in the object's current_xreg attribute"] | list[Annotated[str, "must exist as a key in the object's current_xreg attribute"]] | Literal['all'] | None = None, train_only: bool = False, **kwargs: Any) Forecaster

Adds a forecast to a Forecaster object using the auto_arima function from pmdarima. This function attempts to find the optimal arima order by minimizing information criteria.

Parameters:
Returns:

The passed Forecaster object.

Return type:

(Forecaster)

>>> from scalecast.util import pdr_load
>>> from scalecast.auxmodels import auto_arima
>>> f = pdr_load('HOUSTNSA',start='1900-01-01',end='2021-06-01',future_dates=24)
>>> auto_arima(f,m=12) # saves a model called auto_arima
>>> print(f.auto_arima_params) # access the selected orders

mlp_stack()

scalecast.auxmodels.mlp_stack(f: Forecaster, model_nicknames: list[Annotated[str, "must exist in the name attribute of the object's estimators attribute"]], max_samples: float = 0.9, max_features: float = 0.5, n_estimators: int = 10, hidden_layer_sizes: list[int] = [100, 100, 100], solver: str = 'lbfgs', call_me: str = 'mlp_stack', **kwargs: Any) Forecaster

Applies a stacking model using a bagged MLP regressor as the final estimator and adds it to a Forecaster or MVForecaster object. See what it does: https://scalecast-examples.readthedocs.io/en/latest/sklearn/sklearn.html#StackingRegressor. Recommended to use at least four models in the stack.

Parameters:
  • f (Forecaster or MVForecaster) – The object to add the model to.

  • model_nicknames (list-like) – The names of models previously evaluated within the object.

  • max_samples (float or int) – Default 0.9. The number of samples to draw with replacement from training set to train each base estimator. If int, then draw max_samples samples. If float, then draw that percentage of samples.

  • max_features (float or int) – Default 0.5 The number of features to draw from training set to train each base estimator. If int, then draw max_features features. If float, then draw that percentage of features.

  • n_estimators (int) – Default 10. The number of base estimators in the ensemble.

  • hidden_layer_sizes (tuple) – Default (100,100,100). The layer/hidden layer sizes for the bagged mlp regressor that is the final estimator in the stacked model.

  • solver (str) – Default ‘lbfgs’. The mlp solver.

  • call_me (str) – Default ‘mlp_stack’. The name of the resulting model.

  • **kwargs – Passed to the manual_forecast() method (can include normalizer argument).

Returns:

The passed Forecaster object.

Return type:

Forecaster

>>> from scalecast.auxmodels import mlp_stack
>>> from scalecast import GridGenerator
>>> GridGenerator.get_example_grids()
>>> models = ('xgboost','lightgbm','knn','elasticnet')
>>> f.auto_Xvar_select()
>>> f.tune_test_forecast(models,cross_validate=True)
>>> mlp_stack(f,model_nicknames=models) # saves a model called mlp_stack
>>> f.export('model_summaries',models='mlp_stack')