pyts.multivariate.classification.MultivariateClassifier

class pyts.multivariate.classification.MultivariateClassifier(estimator, weights=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:
estimator : estimator 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.

weights : array-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.

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
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.

Methods

__init__(estimator[, weights]) Initialize self.
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, None, str] =) Request metadata passed to the score method.
__init__(estimator, weights=None)[source]

Initialize self. See help(type(self)) for accurate signature.

fit(X, y)[source]

Fit each classifier.

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

Multivariate time series.

y : None or array-like, shape = (n_samples,)

Class labels.

Returns:
self : object
get_metadata_routing()

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Returns:
routing : MetadataRequest

A MetadataRequest encapsulating routing information.

get_params(deep=True)

Get parameters for this estimator.

Parameters:
deep : bool, default=True

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

Returns:
params : dict

Parameter names mapped to their values.

predict(X)[source]

Predict class labels using hard voting.

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

Multivariate time series.

Returns:
y_pred : array, shape = (n_samples,)

Predicted class labels.

score(X, y, sample_weight=None)

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

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

Multivariate time series.

y : array-like, shape = (n_samples,)

True labels for X.

sample_weight : None or array-like, shape = (n_samples,) (default = None)

Sample weights.

Returns:
score : float

Mean accuracy of self.predict(X) with regards to y.

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:
**params : dict

Estimator parameters.

Returns:
self : estimator instance

Estimator instance.

set_score_request(*, sample_weight: Union[bool, None, str] = '$UNCHANGED$') → pyts.multivariate.classification.multivariate.MultivariateClassifier

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.

New 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_weight : str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for sample_weight parameter in score.

Returns:
self : object

The updated object.