MultivariateClassifier#

class pyts.multivariate.classification.MultivariateClassifier(estimator: _SupportsFitPredict | list[_SupportsFitPredict], weights: ArrayLike | None = None)[source]#

Classifier for multivariate time series.

It provides a convenient class to classify multivariate time series with classifier that can only deal with univariate time series. The labels are predicted in a hard voting fashion using the predictions for each feature.

Parameters:
estimatorestimator object or list thereof

Classifier. If one estimator is provided, it is cloned and each clone performs prediction for one feature. If a list of estimators is provided, each estimator performs prediction for one feature.

weightsarray-like, shape = (n_classifiers,) or None (default=None)

Sequence of weights (float or int) to weight the occurrences of predicted class labels. Uses uniform weights if None.

Attributes:
classes_array, shape = (n_classes,)

An array of class labels known to the classifier.

estimators_list of estimator objects

The collection of fitted classifiers.

Examples

>>> from pyts.classification import BOSSVS
>>> from pyts.datasets import load_basic_motions
>>> from pyts.multivariate.classification import MultivariateClassifier
>>> X_train, X_test, y_train, y_test = load_basic_motions(return_X_y=True)
>>> clf = MultivariateClassifier(BOSSVS())
>>> clf.fit(X_train, y_train)
MultivariateClassifier(...)
>>> clf.score(X_test, y_test)
1.0

Methods

__init__(estimator[, weights])

fit(X, y)

Fit each classifier.

get_metadata_routing()

Get metadata routing of this object.

get_params([deep])

Get parameters for this estimator.

predict(X)

Predict class labels using hard voting.

score(X, y[, sample_weight])

Return the mean accuracy on the given test data and labels.

set_params(**params)

Set the parameters of this estimator.

set_score_request(*[, sample_weight])

Configure whether metadata should be requested to be passed to the score method.

__init__(estimator: _SupportsFitPredict | list[_SupportsFitPredict], weights: ArrayLike | None = None) → None[source]#
fit(X: ArrayLike, y: ArrayLike) → Self[source]#

Fit each classifier.

Parameters:
Xarray-like, shape = (n_samples, n_features, n_timestamps)

Multivariate time series.

yNone or array-like, shape = (n_samples,)

Class labels.

Returns:
selfobject
predict(X: ArrayLike) → NDArray[Any][source]#

Predict class labels using hard voting.

Parameters:
Xarray-like, shape = (n_samples, n_features, n_timestamps)

Multivariate time series.

Returns:
y_predarray, shape = (n_samples,)

Predicted class labels.

set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') → MultivariateClassifier#

Configure whether metadata should be requested to be passed to the score method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the 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.

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

Metadata routing for sample_weight parameter in score.

Returns:
selfobject

The updated object.