MultivariateClassifier#
- class pyts.multivariate.classification.MultivariateClassifier(estimator: _SupportsFitPredict | list[_SupportsFitPredict], weights: ArrayLike | None = None, voting: Literal['hard', 'soft'] = 'hard')[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. A classifier is fitted for each feature, and the labels are predicted by combining the predictions for each feature with hard or soft voting.
- 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 (hard voting) or the class probabilities before averaging (soft voting). Uses uniform weights if None.
- voting{‘hard’, ‘soft’} (default = ‘hard’)
If ‘hard’, uses the predicted class labels for majority rule voting. If ‘soft’, predicts the class label based on the argmax of the (weighted) average of the class probabilities predicted for each feature, which requires every classifier to implement
predict_proba.predict_probais only available with soft voting.
- 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.
- n_features_in_int
Number of features seen during
fit.predictrequires the same number of features.
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, voting])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 or soft voting.
Compute probabilities of possible outcomes for samples in X.
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
scoremethod.- __init__(estimator: _SupportsFitPredict | list[_SupportsFitPredict], weights: ArrayLike | None = None, voting: Literal['hard', 'soft'] = 'hard') 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 or soft voting.
- Parameters:
- Xarray-like, shape = (n_samples, n_features, n_timestamps)
Multivariate time series.
- Returns:
- y_predarray, shape = (n_samples,)
Predicted class labels.
- predict_proba(X: ArrayLike) NDArray[float64][source]#
Compute probabilities of possible outcomes for samples in X.
Only available with soft voting. The class probabilities are the (weighted) average of the class probabilities predicted for each feature.
- Parameters:
- Xarray-like, shape = (n_samples, n_features, n_timestamps)
Multivariate time series.
- Returns:
- y_probaarray, shape = (n_samples, n_classes)
Class probabilities of each sample. The order of the classes is given by the attribute
classes_.
- set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') MultivariateClassifier#
Configure whether metadata should be requested to be passed to the
scoremethod.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(seesklearn.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 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.
- Parameters:
- sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
sample_weightparameter inscore.
- Returns:
- selfobject
The updated object.