linear_regression.py 777 B

123456789101112131415161718192021222324
  1. from typing import Optional
  2. from statsmodels.api import OLS
  3. from flexmeasures.data.models.forecasting.model_spec_factory import (
  4. create_initial_model_specs,
  5. )
  6. """
  7. Simple linear regression by ordinary least squares.
  8. """
  9. # update this version if small things like parametrisation change
  10. version: int = 2
  11. # if a forecasting job using this model fails, fall back on this one
  12. fallback_model_search_term: Optional[str] = "naive"
  13. def ols_specs_configurator(**kwargs):
  14. """Create and customize initial specs with OLS. See model_spec_factory for param docs."""
  15. model_specs = create_initial_model_specs(**kwargs)
  16. model_specs.set_model(OLS)
  17. model_identifier = "linear-OLS model v%d" % version
  18. return model_specs, model_identifier, fallback_model_search_term