models module¶
-
class
models.
DirectAutoRegressor
(base_estimator, auto_order, exog_order, pred_step, exog_delay=None, **base_params)[source]¶ Bases:
fireTS.core.GeneralAutoRegressor
This model performs autoregression with exogenous inputs on the k-step ahead output directly. The model equation is written as follows.
(1)¶\[\begin{split}y(t + k) &=& f(y(t), ..., y(t-p+1), \\ & & x_1(t - d_1), ..., x_1(t-d_1-q_1+1), \\ & & ..., x_m(t - d_1), ..., x_m(t - d_m - q_m + 1)) + e(t)\end{split}\]Parameters: - base_estimator (object) – an estimator object that implements the scikit-learn API (fit, and predict). The estimator will be used to fit the function \(f\) in equation (1).
- auto_order (int) – the autoregression order \(p\) in equation (1).
- exog_order (list) – the exogenous input order, a list of integers representing the order for each exogenous input, i.e. \([q_1, q_2, ..., q_m]\) in equation (1).
- pred_step (int) – the prediction step \(k\) in equation (1). By default, it is set to 1.
- exog_delay (list) – the delays of the exogenous inputs, a list of integers representing the delay of each exogenous input, i.e. \([d_1, d_2, ..., d_m]\) in equation (1). By default, all the delays are set to 0.
- base_params (dict) – other keyword arguments for base_estimator.
-
predict
(X, y)[source]¶ Produce multi-step prediction of y. The multi-step prediction is done directly. No future X inputs are used in the prediction. The prediction equation is as follows:
\[\begin{split}\hat{y}(t + k) &=& f(y(t), ..., y(t - p + 1), \\ & & x_1(t - d_1), ..., x_1(t - d_1 - q_1 + 1) \\ & & ..., x_m(t - d_m), ..., x_m(t - d_m - q_m + 1))\end{split}\]Parameters: - X (array-like) – exogenous input time series, shape = (n_samples, n_exog_inputs)
- y (array-like) – target time series to predict, shape = (n_samples)
- step (int) – prediction step.
Returns: k-step prediction time series, shape = (n_samples). The \(i\) th value of the output is the k-step prediction of the \(i\) th value of the input
y
. The firstpred_step + max(auto_order - 1, max(exog_order + exog_delay) - 1)
values of the output isnp.nan
.
-
score
(X, y, method='r2', verbose=False)[source]¶ Produce multi-step prediction of y, and compute the metrics against y. Nan is ignored when computing the metrics.
Parameters: - X (array-like) – exogenous input time series, shape = (n_samples, n_exog_inputs)
- y (array-like) – target time series to predict, shape = (n_samples)
- method (string) – could be “r2” (R Square) or “mse” (Mean Square Error).
Returns: prediction metric. Nan is ignored when computing the metrics.
-
class
models.
NARX
(base_estimator, auto_order, exog_order, exog_delay=None, **base_params)[source]¶ Bases:
fireTS.core.GeneralAutoRegressor
NARX stands for Nonlinear AutoRegressive eXogenous model. The model equation is written as follows.
(2)¶\[\begin{split}y(t + 1) &=& f(y(t), ..., y(t-p+1), \\ & & x_1(t - d_1), ..., x_1(t-d_1-q_1+1), \\ & & ..., x_m(t - d_1), ..., x_m(t - d_m - q_m + 1)) + e(t)\end{split}\]Parameters: - base_estimator (object) – an estimator object that implements the scikit-learn API (fit, and predict). The estimator will be used to fit the function \(f\) in equation (2).
- auto_order (int) – the autoregression order \(p\) in equation (2).
- exog_order (list) – the exogenous input order, a list of integers representing the order for each exogenous input, i.e. \([q_1, q_2, ..., q_m]\) in equation (2).
- exog_delay (list) – the delays of the exogenous inputs, a list of integers representing the delay of each exogenous input, i.e. \([d_1, d_2, ..., d_m]\) in equation (2). By default, all the delays are set to 0.
- base_params (dict) – other keyword arguments for base_estimator.
-
forecast
(X, y, step=1, X_future=None)[source]¶ Forecast y multiple step ahead given the exogenous input history X, output history y and the future exogenous input X_future. X_future is assumed to be all zeros if not specified.
Parameters: - X (array-like) – exogenous input time series, shape = (n_samples, n_exog_inputs)
- y (array-like) – target time series to predict, shape = (n_samples)
- step (int) – prediction step.
- X_futrue (array-like) – future exogenous input time series, shape = (step - 1, n_exog_inputs)
Returns: multi-step forecasted time series, shape = (step).
-
predict
(X, y, step=1)[source]¶ Produce multi-step prediction of y. The multi-step prediction is done recursively by using the future inputs in X. The prediction equation is as follows:
\[\begin{split}\hat{y}(t + k) &=& f(\hat{y}(t + k - 1), ..., \hat{y}(t + k - p), \\ & &x_1(t + k - 1 - d_1), ..., x_1(t + k - d_1 - q_1) \\ & &..., x_m(t + k - 1 - d_m), ..., x_m(t + k - d_m - q_m))\end{split}\]Parameters: - X (array-like) – exogenous input time series, shape = (n_samples, n_exog_inputs)
- y (array-like) – target time series to predict, shape = (n_samples)
- step (int) – prediction step.
Returns: k-step prediction time series, shape = (n_samples). The \(i\) th value of the output is the k-step prediction of the \(i\) th value of the input
y
. The firststep + max(auto_order - 1, max(exog_order + exog_delay) - 1)
values of the output isnp.nan
.
-
score
(X, y, step=1, method='r2')[source]¶ Produce multi-step prediction of y, and compute the metrics against y. Nan is ignored when computing the metrics.
Parameters: - X (array-like) – exogenous input time series, shape = (n_samples, n_exog_inputs)
- y (array-like) – target time series to predict, shape = (n_samples)
- step (int) – prediction step.
- method (string) – could be “r2” (R Square) or “mse” (Mean Square Error).
Returns: prediction metric. Nan is ignored when computing the metrics.