pyts
pyts is a Python package dedicated to time series classification. It provides preprocessing and utility tools, along with implementations of various time series classification algorithms. The library maintains an active development status, with major versions often introducing new Python support and algorithms, currently at version 0.13.0.
Common errors
-
ModuleNotFoundError: No module named 'pyts'
cause The `pyts` package has not been installed in the current Python environment.fixRun `pip install pyts` to install the library. -
ImportError: cannot import name 'BagOfWords' from 'pyts.bag_of_words'
cause Attempting to import `BagOfWords` expecting its pre-v0.11.0 behavior, or from an incompatible version context.fixFor the functionality of `BagOfWords` before v0.11.0, import `WordExtractor` instead: `from pyts.bag_of_words import WordExtractor`. If you intend to use the newer `BagOfWords` functionality, ensure your `pyts` version is 0.11.0 or newer. -
AttributeError: type object 'MyCustomEstimator' has no attribute '_estimator_type'
cause This can occur when custom `pyts`-compatible estimators or pipelines rely on `scikit-learn`'s internal mixin classes which `pyts` replaced with its own in version 0.12.0. The `_estimator_type` attribute might be expected by `scikit-learn` utilities interacting with `pyts` components, but the internal implementation has changed.fixIf this error occurs after updating `pyts` to v0.12.0 or newer, verify that any custom classes or integrations are compatible with `pyts`'s new internal mixin structure. It may require updating the custom estimator's inheritance or attributes to align with how `pyts` now defines estimator types internally, rather than directly relying on `sklearn`'s private APIs. Ensure that `pyts` estimators are used as intended within `scikit-learn` pipelines, which are generally supported.
Warnings
- breaking Python 3.7 support was dropped in v0.13.0. Python 3.6 support was dropped in v0.12.0, and Python 3.5 in v0.11.0. Ensure your Python environment meets the current requirements.
- breaking The behavior of the `BagOfWords` algorithm was reworked in v0.11.0. If you relied on the old functionality, it has been moved to a new class, `WordExtractor`.
- breaking `pyts` replaced `scikit-learn` mixin classes with its own internal mixin classes in v0.12.0. Custom estimators inheriting from deprecated `sklearn` mixins might encounter issues.
- gotcha Minimal versions of core dependencies (NumPy, SciPy, Scikit-Learn, Joblib, Numba) have been updated significantly in recent releases. Using an older `pyts` with newer dependencies, or a newer `pyts` with older dependencies, can lead to runtime errors or unexpected behavior.
Install
-
pip install pyts
Imports
- TimeSeriesForest
from pyts.classification import TimeSeriesForest
- BagOfWords
from pyts.bag_of_words import BagOfWords # for pre-v0.11.0 behavior
from pyts.bag_of_words import BagOfWords
- WordExtractor
from pyts.bag_of_words import WordExtractor
- load_gunpoint
from pyts.datasets import load_gunpoint
- StandardScaler
from pyts.preprocessing import StandardScaler
- BOSS
from pyts.transformation import BOSS
Quickstart
import numpy as np
from pyts.datasets import load_gunpoint
from pyts.classification import TimeSeriesForest
# Load the GunPoint dataset
X_train, X_test, y_train, y_test = load_gunpoint(return_X_y=True)
# Initialize and train the Time Series Forest classifier
clf = TimeSeriesForest(random_state=43)
clf.fit(X_train, y_train)
# Evaluate the classifier
accuracy = clf.score(X_test, y_test)
print(f"Accuracy of TimeSeriesForest: {accuracy:.4f}")