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