MultiVAR#

class skarf.var.MultiVAR(estimator: BaseVAR, n_jobs: int | None = None)#

Multi-sample VAR model.

Fit a separate VAR model for each sample (e.g. subject) in a dataset.

Parameters:
estimatorestimator object

VAR estimator object.

n_jobsint, default=None

Number of jobs to run in parallel. None means 1 unless in a joblib.parallel_backend context. -1 means using all processors.

Attributes:
estimators_dict of estimators

Dict mapping sample IDs to fit VAR estimators.

n_features_in_int

Number of features seen during fit.

Methods

fit(X[, y, sample_ids])

Fit the model with X.

fit_transform(X[, y])

Fit to data, then transform it.

get_metadata_routing()

Get metadata routing of this object.

get_params([deep])

Get parameters for this estimator.

incremental_fit(X[, y, sample_ids])

Partial model fit for new samples.

predict(X[, sample_ids])

Predict time series values for next time steps.

score(X[, y, sample_ids])

Return the prediction score for the model (by default R2).

set_fit_request(*[, sample_ids])

Request metadata passed to the fit method.

set_output(*[, transform])

Set output container.

set_params(**params)

Set the parameters of this estimator.

set_predict_request(*[, sample_ids])

Request metadata passed to the predict method.

set_score_request(*[, sample_ids])

Request metadata passed to the score method.

set_transform_request(*[, sample_ids])

Request metadata passed to the transform method.

transform(X[, sample_ids])

Return the learned VAR coefficient features for each sample time series.

estimators_: dict[int, BaseVAR]#

Mapping of sample IDs to fit VAR estimators.

fit(X: ndarray | Series, y: None = None, sample_ids: ndarray | None = None, **params) Self#

Fit the model with X.

Parameters:
Xarray-like of shape (n_samples, sequence_length, n_features)

Array of multiple training multivariate time series. If the sequences are different length, X should be a 1D ndarray of dtype object, where each element is a 2D array. X may also be a pandas Series object, with its index encoding each sample ID (e.g. subject ID).

yIgnored

Ignored

sample_idsarray of shape (n_samples,), default=None

Array of sample IDs (e.g. subject ID) for each training time series. If None, the sample IDs will be extracted from the index of X in case X is a Series. Otherwise, sample IDs 0, ..., n_samples - 1 are assumed.

**paramsdict of str -> object

Parameters to pass through to the underlying VAR fit() method.

Returns:
selfobject

Returns the instance itself.

fit_transform(X, y=None, **fit_params)#

Fit to data, then transform it.

Fits transformer to X and y with optional parameters fit_params and returns a transformed version of X.

Parameters:
Xarray-like of shape (n_samples, n_features)

Input samples.

yarray-like of shape (n_samples,) or (n_samples, n_outputs), default=None

Target values (None for unsupervised transformations).

**fit_paramsdict

Additional fit parameters.

Returns:
X_newndarray array of shape (n_samples, n_features_new)

Transformed array.

get_metadata_routing()#

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Returns:
routingMetadataRequest

A MetadataRequest encapsulating routing information.

get_params(deep=True)#

Get parameters for this estimator.

Parameters:
deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:
paramsdict

Parameter names mapped to their values.

incremental_fit(X: ndarray | Series, y: None = None, sample_ids: ndarray | None = None, **params) Self#

Partial model fit for new samples.

Parameters:
Xarray-like of shape (n_samples, sequence_length, n_features)

Array of multiple multivariate time series. If the sequences are different length, X should be a 1D ndarray of dtype object, where each element is a 2D array. X may also be a pandas Series object, with its index encoding each sample ID (e.g. subject ID). Should contain new sample time series not in training data.

yIgnored

Ignored

sample_idsarray of shape (n_samples,), default=None

Array of sample IDs (e.g. subject ID) for each training time series. If None, the sample IDs will be extracted from the index of X in case X is a Series. Otherwise, sample IDs 0, ..., n_samples - 1 are assumed. Should contain new sample IDs not in training data.

**paramsdict of str -> object

Parameters to pass through to the underlying VAR fit() method.

Returns:
selfobject

Returns the instance itself.

n_features_in_: int#

Number of features seen during fit.

predict(X: ndarray | Series, sample_ids: ndarray | None = None) ndarray#

Predict time series values for next time steps.

Parameters:
Xarray-like of shape (n_samples, sequence_length, n_features)

Array of multiple multivariate time series. If the sequences are different length, X should be a 1D ndarray of dtype object, where each element is a 2D array. X may also be a pandas Series object, with its index encoding each sample ID (e.g. subject ID).

sample_idsarray of shape (n_samples,), default=None

Array of sample IDs (e.g. subject ID) for each training time series. If None, the sample IDs will be extracted from the index of X in case X is a Series. Otherwise, sample IDs 0, ..., n_samples - 1 are assumed.

Returns:
X_predarray-like of shape (n_samples, sequence_length, n_features)

Next time step predictions for each input time series in X. For each time series, the estimator for the corresponding sample ID is used for prediction.

score(X: ndarray | Series, y: None = None, sample_ids: ndarray | None = None, **params) float#

Return the prediction score for the model (by default R2).

Parameters:
Xarray-like of shape (n_samples, sequence_length, n_features)

Array of multiple multivariate time series. If the sequences are different length, X should be a 1D ndarray of dtype object, where each element is a 2D array. X may also be a pandas Series object, with its index encoding each sample ID (e.g. subject ID).

yIgnored

Ignored

sample_idsarray of shape (n_samples,), default=None

Array of sample IDs (e.g. subject ID) for each training time series. If None, the sample IDs will be extracted from the index of X in case X is a Series. Otherwise, sample IDs 0, ..., n_samples - 1 are assumed.

**paramsdict of str -> object

Parameters to pass through to the underlying VAR score() method.

Returns:
score: float

Mean VAR prediction score (by default R2, see estimator.scoring_function).

set_fit_request(*, sample_ids: bool | None | str = '$UNCHANGED$') MultiVAR#

Request metadata passed to the fit method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
sample_idsstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for sample_ids parameter in fit.

Returns:
selfobject

The updated object.

set_output(*, transform=None)#

Set output container.

See Introducing the set_output API for an example on how to use the API.

Parameters:
transform{“default”, “pandas”, “polars”}, default=None

Configure output of transform and fit_transform.

  • "default": Default output format of a transformer

  • "pandas": DataFrame output

  • "polars": Polars output

  • None: Transform configuration is unchanged

Added in version 1.4: "polars" option was added.

Returns:
selfestimator instance

Estimator instance.

set_params(**params)#

Set the parameters of this estimator.

The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.

Parameters:
**paramsdict

Estimator parameters.

Returns:
selfestimator instance

Estimator instance.

set_predict_request(*, sample_ids: bool | None | str = '$UNCHANGED$') MultiVAR#

Request metadata passed to the predict method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to predict if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to predict.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
sample_idsstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for sample_ids parameter in predict.

Returns:
selfobject

The updated object.

set_score_request(*, sample_ids: bool | None | str = '$UNCHANGED$') MultiVAR#

Request metadata passed to the score method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
sample_idsstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for sample_ids parameter in score.

Returns:
selfobject

The updated object.

set_transform_request(*, sample_ids: bool | None | str = '$UNCHANGED$') MultiVAR#

Request metadata passed to the transform method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to transform if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to transform.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
sample_idsstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for sample_ids parameter in transform.

Returns:
selfobject

The updated object.

transform(X: ndarray | Series, sample_ids: ndarray | None = None) ndarray#

Return the learned VAR coefficient features for each sample time series.

Parameters:
Xarray-like of shape (n_samples, sequence_length, n_features)

Array of multiple multivariate time series. If the sequences are different length, X should be a 1D ndarray of dtype object, where each element is a 2D array. X may also be a pandas Series object, with its index encoding each sample ID (e.g. subject ID). All sample time series should already be fit with fit() or incremental_fit().

sample_idsarray of shape (n_samples,), default=None

Array of sample IDs (e.g. subject ID) for each training time series. If None, the sample IDs will be extracted from the index of X in case X is a Series. Otherwise, sample IDs 0, ..., n_samples - 1 are assumed. All sample IDs should have already been seen during fit() or incremental_fit().

Returns:
coefarray of shape (n_samples, order, n_features, n_features)

Array of VAR coefficients for each sample time series, to use as features.