class AutoARIMA(ExtendedForecastingModel): def __init__(self, *autoarima_args, **autoarima_kwargs): """ Auto-ARIMA This implementation is a thin wrapper around `pmdarima.txt AutoARIMA model <https://alkaline-ml.com/pmdarima/modules/generated/pmdarima.arima.AutoARIMA.html>`_, which provides functionality similar to R's `auto.arima <https://www.rdocumentation.org/packages/forecast/versions/7.3/topics/auto.arima>`_. This model supports the same parameters as the pmdarima.txt AutoARIMA model. See `pmdarima.txt documentation <https://alkaline-ml.com/pmdarima/modules/generated/pmdarima.arima.AutoARIMA.html>`_ for an extensive documentation and a list of supported parameters. Parameters ---------- autoarima_args Positional arguments for the pmdarima.txt AutoARIMA model autoarima_kwargs Keyword arguments for the pmdarima.txt AutoARIMA model """ super().__init__() self.model = PmdAutoARIMA(*autoarima_args, **autoarima_kwargs) self.trend = self.model.trend def __str__(self): return 'Auto-ARIMA' def fit(self, series: TimeSeries, exog: Optional[TimeSeries] = None): super().fit(series, exog) series = self.training_series self.model.fit(series.values(), X=exog.values() if exog else None) def predict(self, n: int, exog: Optional[TimeSeries] = None, num_samples: int = 1): super().predict(n, exog, num_samples) forecast = self.model.predict(n_periods=n, X=exog.values() if exog else None) return self._build_forecast_series(forecast) @property def min_train_series_length(self) -> int: return 30 def _supports_range_index(self) -> bool: raise_if( self.trend and self.trend != "c", "'trend' is not None. Range indexing is not supported in that case.", logger) return True
def create_model(self, **kwargs): if self.kind == ModelT.holt_winters.name: data = self.node.item model = ExponentialSmoothing(endog=data, **kwargs) elif self.kind == ModelT.auto_arima.name: try: from pmdarima import AutoARIMA except ImportError: # pragma: no cover logger.error( "pmdarima not installed, so auto_arima won't work. Exiting." "Install it with: pip install scikit-hts[auto_arima]") return model = AutoARIMA(**kwargs) elif self.kind == ModelT.sarimax.name: as_df = self.node.item end = self.node.get_series() if self.node.exogenous: ex = as_df[self.node.exogenous] else: ex = None model = SARIMAX(endog=end, exog=ex, **kwargs) else: raise return model
def __init__(self, *autoarima_args, **autoarima_kwargs): """Auto-ARIMA This implementation is a thin wrapper around `pmdarima AutoARIMA model <https://alkaline-ml.com/pmdarima/modules/generated/pmdarima.arima.AutoARIMA.html>`_, which provides functionality similar to R's `auto.arima <https://www.rdocumentation.org/packages/forecast/versions/7.3/topics/auto.arima>`_. This model supports the same parameters as the pmdarima AutoARIMA model. See `pmdarima documentation <https://alkaline-ml.com/pmdarima/modules/generated/pmdarima.arima.AutoARIMA.html>`_ for an extensive documentation and a list of supported parameters. .. note:: For a faster and probabilistic version of AutoARIMA, checkout the :class:`StatsForecastAutoARIMA` model. Parameters ---------- autoarima_args Positional arguments for the pmdarima.AutoARIMA model autoarima_kwargs Keyword arguments for the pmdarima.AutoARIMA model """ super().__init__() self.model = PmdAutoARIMA(*autoarima_args, **autoarima_kwargs) self.trend = self.model.trend
class AutoARIMA(UnivariateForecastingModel): def __init__(self, *autoarima_args, **autoarima_kwargs): """ Auto-ARIMA This implementation is a thin wrapper around `pmdarima.txt AutoARIMA model <https://alkaline-ml.com/pmdarima/modules/generated/pmdarima.arima.AutoARIMA.html>`_, which provides functionality similar to R's `auto.arima <https://www.rdocumentation.org/packages/forecast/versions/7.3/topics/auto.arima>`_. This model supports the same parameters as the pmdarima.txt AutoARIMA model. See `pmdarima.txt documentation <https://alkaline-ml.com/pmdarima/modules/generated/pmdarima.arima.AutoARIMA.html>`_ for an extensive documentation and a list of supported parameters. Parameters ---------- autoarima_args Positional arguments for the pmdarima.txt AutoARIMA model autoarima_kwargs Keyword arguments for the pmdarima.txt AutoARIMA model """ super().__init__() self.model = PmdAutoARIMA(*autoarima_args, **autoarima_kwargs) def __str__(self): return 'Auto-ARIMA' def fit(self, series: TimeSeries): super().fit(series) series = self.training_series self.model.fit(series.values()) def predict(self, n): super().predict(n) forecast = self.model.predict(n_periods=n) return self._build_forecast_series(forecast) @property def min_train_series_length(self) -> int: return 30
def create_model(self, **kwargs): if self.kind == Model.holt_winters.name: data = self.node.item model = ExponentialSmoothing(endog=data, **kwargs) elif self.kind == Model.auto_arima.name: model = AutoARIMA(**kwargs) elif self.kind == Model.sarimax.name: as_df = self.node.item end = self.node.get_series() if self.node.exogenous: ex = as_df[self.node.exogenous] else: ex = None model = SARIMAX(endog=end, exog=ex, **kwargs) else: raise return model
series_count=3, series_size=365 * 3, start_dt="2019-01-01", days_period=1, ) training_data = generated_data.df group_key_columns = generated_data.key_columns pipeline = Pipeline( steps=[ ( "arima", AutoARIMA( max_order=14, out_of_sample_size=90, suppress_warnings=True, error_action="ignore", ), ) ] ) diff_analyzer = PmdarimaAnalyzer( df=training_data, group_key_columns=group_key_columns, y_col="y", datetime_col="ds", ) ndiff = diff_analyzer.calculate_ndiffs( alpha=0.05, test="kpss",
class AutoARIMA(DualCovariatesForecastingModel): def __init__(self, *autoarima_args, **autoarima_kwargs): """Auto-ARIMA This implementation is a thin wrapper around `pmdarima AutoARIMA model <https://alkaline-ml.com/pmdarima/modules/generated/pmdarima.arima.AutoARIMA.html>`_, which provides functionality similar to R's `auto.arima <https://www.rdocumentation.org/packages/forecast/versions/7.3/topics/auto.arima>`_. This model supports the same parameters as the pmdarima AutoARIMA model. See `pmdarima documentation <https://alkaline-ml.com/pmdarima/modules/generated/pmdarima.arima.AutoARIMA.html>`_ for an extensive documentation and a list of supported parameters. .. note:: For a faster and probabilistic version of AutoARIMA, checkout the :class:`StatsForecastAutoARIMA` model. Parameters ---------- autoarima_args Positional arguments for the pmdarima.AutoARIMA model autoarima_kwargs Keyword arguments for the pmdarima.AutoARIMA model """ super().__init__() self.model = PmdAutoARIMA(*autoarima_args, **autoarima_kwargs) self.trend = self.model.trend def __str__(self): return "Auto-ARIMA" def _fit(self, series: TimeSeries, future_covariates: Optional[TimeSeries] = None): super()._fit(series, future_covariates) series = self.training_series self.model.fit( series.values(), X=future_covariates.values() if future_covariates else None) return self def _predict( self, n: int, future_covariates: Optional[TimeSeries] = None, num_samples: int = 1, ): super()._predict(n, future_covariates, num_samples) forecast = self.model.predict( n_periods=n, X=future_covariates.values() if future_covariates else None) return self._build_forecast_series(forecast) @property def min_train_series_length(self) -> int: return 10 def _supports_range_index(self) -> bool: raise_if( self.trend and self.trend != "c", "'trend' is not None. Range indexing is not supported in that case.", logger, ) return True