tslearn
A machine learning toolkit dedicated to time-series data
What it is and what it does
tslearn is a machine learning toolkit built on top of scikit-learn, numpy, scipy, and numba that specializes in time series data. It provides clustering (TimeSeriesKMeans), classification (KNeighborsTimeSeriesClassifier), regression, and distance metrics including Dynamic Time Warping. The package expects time series as 3D numpy arrays and handles variable-length sequences.
The library integrates seamlessly with scikit-learn's ecosystem, supporting pipelines and hyperparameter tuning. It includes utilities for data preprocessing (scaling, resampling, piecewise transformations), dataset loading (UCR datasets), and analysis tasks like computing barycenters. Models follow scikit-learn's fit/predict API, making it accessible to developers already familiar with that framework.
Use it for:
- Classify time series sequences using k-nearest neighbors with time-aware distance metrics
- Cluster temporal data with TimeSeriesKMeans to find similar patterns across time series
- Measure similarity between time series using Dynamic Time Warping or other specialized metrics
- Preprocess variable-length time series with scaling and resampling before model training
- Build scikit-learn pipelines combining time series preprocessing and classification steps
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
tslearn provides machine learning algorithms optimized for time series data, including clustering, classification, regression, and distance metrics like Dynamic Time Warping, built on scikit-learn's API.
Yes. tslearn is actively maintained, has no known vulnerabilities, uses permissive licensing, and offers low installation friction. It fills a clear gap for time series machine learning with scikit-learn compatibility. Install if you need specialized time series algorithms; skip if your use case fits standard scikit-learn or you require production-grade time series forecasting.
Install
tslearn on PyPI
pip
pip install tslearnuv
uv add tslearnpoetry
poetry add tslearnInstalling tslearn
Before you install
Low friction: pure Python wheel with well-established dependencies (scikit-learn, numpy, scipy, numba, joblib, statsmodels). Active maintenance with last commit 2026-08-13 and release 43 days ago.
License in practice
BSD-2-Clause (permissive) allows commercial and private use with minimal restrictions; attribution required.
Quickstart
pip install tslearn
from tslearn.utils import to_time_series_dataset
from tslearn.neighbors import KNeighborsTimeSeriesClassifier
X = to_time_series_dataset([[1, 3, 4, 2], [1, 2, 4, 2]])
knn = KNeighborsTimeSeriesClassifier(n_neighbors=1)
knn.fit(X, [0, 1])
Requires Python >= 3.10
Verify before relying
- Whether numba JIT compilation is required for acceptable performance on large datasets
- Specific performance characteristics compared to alternative time series libraries
Package facts
| License | BSD-2-Clause (permissive) |
| Python support | supports the current Python release (>=3.10) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 6 — scikit-learn, numpy, scipy, numba, joblib, statsmodels |
| Maintenance | actively maintained — 43 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 313,462/month — #7,714 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: tslearn-0.9.0-py3-none-any.whl
Tags
More Libraries packages
urllib3 is an HTTP client library that provides…
permissive · top 100 on PyPI
requestsRequests is a Python HTTP library that…
permissive · top 100 on PyPI
pluggyPluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
python-dateutilProvides parsing, arithmetic, and recurrence…
permissive · top 100 on PyPI
sixSix provides utility functions to write Python…
permissive · top 100 on PyPI
pytestpytest is a testing framework that lets you…
permissive · top 100 on PyPI
dtaidistanceComputes distance measures between time series…
permissive · top 15,000 on PyPI
riverRiver provides online machine learning…
permissive · top 15,000 on PyPI
sktimesktime provides a unified interface for time…
permissive · top 5,000 on PyPI
pytsPyts provides time series classification…
permissive · top 15,000 on PyPI
dtw-pythonComputes Dynamic Time Warping alignments…
copyleft · top 15,000 on PyPI
ai4tsAI4TS provides a framework for building machine…
permissive · top 15,000 on PyPI
pypotsPyPOTS provides machine learning algorithms for…
permissive · top 15,000 on PyPI
fairlearnFairlearn assesses and mitigates fairness…
permissive · top 15,000 on PyPI
tsdbTSDB downloads and loads 173 open-source…
permissive · top 15,000 on PyPI
tsdownsampleDownsamples large time series datasets to a…
permissive · top 15,000 on PyPI