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.
Nonemeans 1 unless in ajoblib.parallel_backendcontext.-1means 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 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
fitmethod.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
predictmethod.set_score_request(*[, sample_ids])Request metadata passed to the
scoremethod.set_transform_request(*[, sample_ids])Request metadata passed to the
transformmethod.transform(X[, sample_ids])Return the learned VAR coefficient features for each sample time series.
- 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,
Xshould be a 1D ndarray of dtype object, where each element is a 2D array.Xmay also be a pandasSeriesobject, 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 ofXin caseXis aSeries. Otherwise, sample IDs0, ..., n_samples - 1are 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
Xandywith optional parametersfit_paramsand returns a transformed version ofX.- 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
MetadataRequestencapsulating 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,
Xshould be a 1D ndarray of dtype object, where each element is a 2D array.Xmay also be a pandasSeriesobject, 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 ofXin caseXis aSeries. Otherwise, sample IDs0, ..., n_samples - 1are 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.
- 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,
Xshould be a 1D ndarray of dtype object, where each element is a 2D array.Xmay also be a pandasSeriesobject, 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 ofXin caseXis aSeries. Otherwise, sample IDs0, ..., n_samples - 1are 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,
Xshould be a 1D ndarray of dtype object, where each element is a 2D array.Xmay also be a pandasSeriesobject, 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 ofXin caseXis aSeries. Otherwise, sample IDs0, ..., n_samples - 1are 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
fitmethod.Note that this method is only relevant if
enable_metadata_routing=True(seesklearn.set_config()). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed tofitif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it tofit.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_idsparameter infit.
- 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
transformandfit_transform."default": Default output format of a transformer"pandas": DataFrame output"polars": Polars outputNone: 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
predictmethod.Note that this method is only relevant if
enable_metadata_routing=True(seesklearn.set_config()). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed topredictif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it topredict.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_idsparameter inpredict.
- Returns:
- selfobject
The updated object.
- set_score_request(*, sample_ids: bool | None | str = '$UNCHANGED$') MultiVAR#
Request metadata passed to the
scoremethod.Note that this method is only relevant if
enable_metadata_routing=True(seesklearn.set_config()). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed toscoreif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it toscore.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_idsparameter inscore.
- Returns:
- selfobject
The updated object.
- set_transform_request(*, sample_ids: bool | None | str = '$UNCHANGED$') MultiVAR#
Request metadata passed to the
transformmethod.Note that this method is only relevant if
enable_metadata_routing=True(seesklearn.set_config()). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed totransformif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it totransform.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_idsparameter intransform.
- 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,
Xshould be a 1D ndarray of dtype object, where each element is a 2D array.Xmay also be a pandasSeriesobject, with its index encoding each sample ID (e.g. subject ID). All sample time series should already be fit withfit()orincremental_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 ofXin caseXis aSeries. Otherwise, sample IDs0, ..., n_samples - 1are assumed. All sample IDs should have already been seen duringfit()orincremental_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.