Comments (5)
AutoARIMA's fit
takes in a dataframe containing the columns ds, unique_id, y, ex_1, ex_2, ...., ex_n
. The first three are the timestamp, the id of the timeseries and the value of the time series. Thereafter, the exogenous variables follow. Note that you can have arbitrary column names for these exogenous variables.
AutoARIMA's predict
(which I assume you're referring to in your question) can take an input X_df
for future exogenous inputs. This dataframe should have the columns ds, unique_id, ex_1, ex_2, ...., ex_n
. So, it basically contains the same columns as your training dataset, except for the target value.
How many rows should X_df
have? Suppose you're predicting two timeseries, with a horizon of 12
. Then, X_df
should (at least) contain 12 * 2 = 24 rows, each row representing a set of future exogenous variables for the forecast horizon for one of the time series.
Let me know if this helps, and if not, please provide a (minimal) example of your code so that I can reproduce your issue.
from statsforecast.
Hi @elephaint,
Thanks for your quick reply. I think what you mean is using the StatsForecast class for this, right? Maybe also, just to clarify, the future exogenous inputs (X_df) are incorporated into the forecast by the current time stamp (so it does not consider values further than forecast horizon)? But the exo features provided during fit are also future exogenous features?
I tried integrating the AutoARIMA class into my forecasting pipeline, which uses another packages TimeSeries class, for data representation.
Basically, what I am after is having the ability to evaluate the fitted model on different datasets. Mainly due to comparability with other ML models. This is also why I chose the forward method (says per documentation that this works for predicting different/new series).
The snippet below works fine if no future exogenous variables are provided. However, it would be a nice addition for me.
class AutoARIMA:
def __init__(self, *autoarima_args, **autoarima_kwargs):
self.model = AutoARIMA(*autoarima_args, **autoarima_kwargs)
def fit(self, series: TimeSeries, future_covariates: Optional[TimeSeries] = None):
self.model.fit(
y=np.squeeze(series[0].values(copy=False)),
X=future_covariates.values(copy=False) if future_covariates else None,
)
return self
def predict(
self,
n: int,
series: Optional[TimeSeries] = None,
future_covariates: Optional[TimeSeries] = None,
num_samples: int = 1,
verbose: bool = False,
):
y = np.squeeze(series.values(copy=False))
forecast_dict = self.model.forward(
h=n,
y=y,
X=future_covariates.values(copy=False) if future_covariates else None,
level=(one_sigma_rule,),
)
mu, std = unpack_sf_dict(forecast_dict)
if num_samples > 1:
samples = create_normal_samples(mu, std, num_samples, n)
else:
samples = mu
return _build_forecast_series(samples, input_series=series)
````
from statsforecast.
Edit: So fitting works fine, if y and X have the same shape (after slicing the future exogenous regressors).
For forwards method, I still get either a shape error or xreg error.
from statsforecast.
@elephaint It seems like I got this to work now. Seems like I missunderstood the doc. X are the exogenous features for the series supplied in y and X_future those for the horizon.
Does this look plausible to you? Maybe you can also help me understand the difference between forecast and forward. Does forecast fit the model again to the newly provided series?
Thx for your help.
def predict(
self,
n: int,
series: Optional[TimeSeries] = None,
future_covariates: Optional[TimeSeries] = None,
num_samples: int = 1,
verbose: bool = False,
):
forecast_dict = self.model.forward(
h=n,
y=np.squeeze(series[0].values(copy=False)),
X=future_covariates[0].drop_before(series[0].start_time() - timedelta(days=1)).drop_after(series[0].end_time() + timedelta(days=1)).values(copy=False) if future_covariates else None,
X_future=future_covariates[0].drop_before(series[0].end_time()).drop_after(n).values(copy=False) if future_covariates else None,
level=(one_sigma_rule,),
)
from statsforecast.
Indeed, your understanding of the exogenous is now correct.
Code seems plausible; You're right about the difference between forward
and forecast
: the latter will fit the model again.
from statsforecast.
Related Issues (20)
- Nixtla statsforecast/statsmodels failing to import polars HOT 3
- Independency of Time Series with Different Unique IDs HOT 2
- Statsforecat.predict expects wrong dataframe shape on X_df HOT 10
- Add a check for fitting a theta model with less than two seasonal periods
- Missing Amazon Forecast results in the experiment docs HOT 4
- AttributeError: 'bool' object has no attribute 'n_windows' when adding confidence level HOT 4
- SeasonalNaive forecasts are not as expected; expected lag 12 but forecast is rounded and slightly off HOT 2
- Getting error when training AutoCES on covid deaths dataset from gluonts HOT 3
- StatsForecast: No model able to be fitted HOT 1
- Can statsforecast detect season_length automatically? HOT 2
- ValueError: xreg is rank deficient HOT 4
- Models: documented public methods/attributes to extract best parameters for Auto* models HOT 3
- Auto_Ces "Exception: no model able to be fitted" HOT 4
- Problem getting fitted values using cross validation with a spark dataframe HOT 2
- Problem using fit and predict or fit_predict using a spark dataframe HOT 1
- Model evaluation documentation asserts that datasetsforecast is required, but it isn't HOT 2
- Deprecate references to custom `evaluate_performace` function in favor of `utilsforecast.evaluation.evaluate`? HOT 2
- Should `forecast_fitted_values` also work for fitted models in addition to when forecast(fitted=True) is called? HOT 1
- Dead links for several pages in docs HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from statsforecast.