| Type | Default | Details | |
|---|---|---|---|
| target_cols | List[str] | List of target column names to model. | |
| lags | Dict[str, Union[int, List[int]]] | Dictionary specifying lags for each target variable. Values can be an int (number of lags) or a list of specific lag indices. | |
| lag_transform | Optional[Dict[str, list]] | None | Dictionary specifying lag-transform functions for each target variable. Each value is a list of transformation functions (e.g., rolling_mean, expanding_std) to apply to the lagged features of that target. |
| difference | Optional[Dict[str, int]] | None | Dictionary specifying the order of ordinary differencing to apply to each target variable. Values are integers indicating how many times to difference the series. |
| seasonal_diff | Optional[Dict[str, int]] | None | Dictionary specifying the seasonal period for seasonal differencing for each target variable. Values are integers indicating the seasonal lag (e.g., 12 for monthly data with yearly seasonality). |
| trend | Optional[Dict[str, str]] | None | Dictionary specifying the trend strategy for each target variable. Values can be ‘linear’ for linear trend removal or ‘ets’ for ETS-based trend removal. |
| pol_degree | Optional[Union[int, Dict[str, int]]] | 1 | Polynomial degree for linear trend removal. Can be a single integer applied to all targets or a dictionary specifying the degree for each target. |
| ets_params | Optional[Dict[str, Any]] | None | Dictionary specifying ETS model and fit parameters for each target variable when using ‘ets’ trend removal. Each value is a dictionary of parameters for the ExponentialSmoothing model and fitting process. |
| change_points | Optional[Dict[str, List[int]]] | None | Dictionary specifying change points for piecewise linear trend removal for each target variable. Values are lists of integer indices indicating where the trend should change. Only applicable when trend strategy is ‘linear’. |
| box_cox | Optional[Dict[str, Union[bool, float, int]]] | None | Dictionary specifying whether to apply Box-Cox transformation to each target variable. Values can be a boolean (True to apply, False to skip) or a float (lambda parameter for Box-Cox transformation). If True, lambda will be estimated from the data. |
| box_cox_biasadj | Union[bool, Dict[str, bool]] | False | Whether to apply bias adjustment when inverting the Box-Cox transformation on forecasts. Can be a single boolean applied to all targets or a dictionary specifying the bias adjustment for each target. |
| add_constant | bool | True | If True, a constant column will be added to the regressor matrix for the VAR model. This is typically used to allow for an intercept in the model. |
| cat_variables | Optional[List[str]] | None | List of categorical feature column names to encode. These will be shared across all target variables. |
| categorical_encoder | Optional[Union[Dict[str, Any], Any]] | None | A categorical encoder instance, or a single-entry dictionary mapping the target column to the encoder when the encoder requires access to the target variable during fitting (e.g. {target_col: MeanEncoder()}). If encoder requiring target access is provided directly without the dict format, first target column in target_cols will be used for fitting the encoder. For encoders that do not require target access, pass the encoder instance directly (e.g. OneHotEncoder()). |
| verbose | bool | False | If True, the model will print verbose messages. |
| Returns | None |
var
def var(
target_cols:List[str], # List of target column names to model.
lags:Dict[str, Union[int, List[int]]], # Dictionary specifying lags for each target variable. Values can be an int (number of lags) or a list of specific lag indices.
lag_transform:Optional[Dict[str, list]]=None, # Dictionary specifying lag-transform functions for each target variable. Each value is a list of transformation functions (e.g., rolling_mean, expanding_std) to apply to the lagged features of that target.
difference:Optional[Dict[str, int]]=None, # Dictionary specifying the order of ordinary differencing to apply to each target variable. Values are integers indicating how many times to difference the series.
seasonal_diff:Optional[Dict[str, int]]=None, # Dictionary specifying the seasonal period for seasonal differencing for each target variable. Values are integers indicating the seasonal lag (e.g., 12 for monthly data with yearly seasonality).
trend:Optional[Dict[str, str]]=None, # Dictionary specifying the trend strategy for each target variable. Values can be 'linear' for linear trend removal or 'ets' for ETS-based trend removal.
pol_degree:Optional[Union[int, Dict[str, int]]]=1, # Polynomial degree for linear trend removal. Can be a single integer applied to all targets or a dictionary specifying the degree for each target.
ets_params:Optional[Dict[str, Any]]=None, # Dictionary specifying ETS model and fit parameters for each target variable when using 'ets' trend removal. Each value is a dictionary of parameters for the ExponentialSmoothing model and fitting process.
change_points:Optional[Dict[str, List[int]]]=None, # Dictionary specifying change points for piecewise linear trend removal for each target variable. Values are lists of integer indices indicating where the trend should change. Only applicable when trend strategy is 'linear'.
box_cox:Optional[Dict[str, Union[bool, float, int]]]=None, # Dictionary specifying whether to apply Box-Cox transformation to each target variable. Values can be a boolean (True to apply, False to skip) or a float (lambda parameter for Box-Cox transformation). If True, lambda will be estimated from the data.
box_cox_biasadj:Union[bool, Dict[str, bool]]=False, # Whether to apply bias adjustment when inverting the Box-Cox transformation on forecasts. Can be a single boolean applied to all targets or a dictionary specifying the bias adjustment for each target.
add_constant:bool=True, # If True, a constant column will be added to the regressor matrix for the VAR model. This is typically used to allow for an intercept in the model.
cat_variables:Optional[List[str]]=None, # List of categorical feature column names to encode. These will be shared across all target variables.
categorical_encoder:Optional[Union[Dict[str, Any], Any]]=None, # A categorical encoder instance, or a single-entry dictionary mapping the target column to the encoder when the encoder requires access to the target variable during fitting (e.g. {target_col: MeanEncoder()}). If encoder requiring target access is provided directly without the dict format, first target column in target_cols will be used for fitting the encoder. For encoders that do not require target access, pass the encoder instance directly (e.g. OneHotEncoder()).
verbose:bool=False, # If True, the model will print verbose messages.
)->None:
“ Initialize the VAR model with specified preprocessing and modeling parameters.
var.fit
def fit(
df:pd.DataFrame, # Training DataFrame containing the target and any feature columns.
)->None:
Fit the VAR model to the provided DataFrame.
| Type | Details | |
|---|---|---|
| df | pd.DataFrame | Training DataFrame containing the target and any feature columns. |
| Returns | None |
var.forecast
def forecast(
H:int, # Forecast horizon (number of steps ahead to predict).
exog:Optional[pd.DataFrame]=None, # Future exogenous regressors (must contain at least H rows).
)->Dict[str, np.ndarray]: # Forecasted values for each target, keyed by column name.
Generate forecasts for H future time steps.
| Type | Default | Details | |
|---|---|---|---|
| H | int | Forecast horizon (number of steps ahead to predict). | |
| exog | Optional[pd.DataFrame] | None | Future exogenous regressors (must contain at least H rows). |
| Returns | Dict[str, np.ndarray] | Forecasted values for each target, keyed by column name. |
var.cross_validate
def cross_validate(
df:pd.DataFrame, # Input dataframe.
target_col:str, # Target variable for evaluation.
cv_split:int, # Number of cross-validation folds.
test_size:int, # Test size per fold.
metrics:List[Callable], # Metric functions (e.g. ``[MAE, RMSE]``) used to evaluate forecast accuracy across folds. Call ``.cv_summary()`` after cross-validation to retrieve the aggregated scores.
step_size:int=1, # Step size for rolling window. Default is 1.
h_split_point:Optional[int]=None, # Point to split the test set for separate evaluation. Default is None.
)->Union[pd.DataFrame, Tuple[pd.DataFrame, pd.DataFrame]]: # DataFrame with averaged cross-validation metric scores.
Perform cross-validation.
| Type | Default | Details | |
|---|---|---|---|
| df | pd.DataFrame | Input dataframe. | |
| target_col | str | Target variable for evaluation. | |
| cv_split | int | Number of cross-validation folds. | |
| test_size | int | Test size per fold. | |
| metrics | List[Callable] | Metric functions (e.g. [MAE, RMSE]) used to evaluate forecast accuracy across folds. Call .cv_summary() after cross-validation to retrieve the aggregated scores. |
|
| step_size | int | 1 | Step size for rolling window. Default is 1. |
| h_split_point | Optional[int] | None | Point to split the test set for separate evaluation. Default is None. |
| Returns | Union[pd.DataFrame, Tuple[pd.DataFrame, pd.DataFrame]] | DataFrame with averaged cross-validation metric scores. |