Package: tslearn
tslearnThe machine learning toolkit for time series analysis in PythonSectionDescriptionInstallationInstalling the dependencies and tslearnGetting startedA quick introduction on how to use tslearnAvailable featuresAn extensive overview of tslearn's functionalitiesDocumentationA link to our API reference and a gallery of examplesContributingA guide for heroes willing to contributeCitationA citation for tslearn for scholarly articlesInstallationThere are different alternatives to install tslearn:PyPi:python -m pip install tslearnConda:conda install -c conda-forge tslearnGit:python -m pip install https://github.com/tslearn-team/tslearn/archive/main.zipIn order for the installation to be successful, the required dependencies must be installed. For a more detailed guide on how to install tslearn, please see theDocumentation.Getting started1. Getting the data in the right formattslearn expects a time series dataset to be formatted as a 3Dnumpyarray. The three dimensions correspond to the number of time series, the number of measurements per time series and the number of dimensions respectively (n_ts, max_sz, d). In order to get the data in the right format, different solutions exist:You can use the utility functions such asto_time_series_dataset.You can convert from other popular time series toolkits in Python.You can load any of the UCR datasets in the required format.You can generate synthetic data using thegeneratorsmodule.It should further be noted that tslearnsupports variable-length timeseries.>>>fromtslearn.utilsimportto_time_series_dataset>>>my_first_time_series=[1,3,4,2]>>>my_second_time_series=[1,2,4,2]>>>my_third_time_series=[1,2,4,2,2]>>>X=to_time_series_dataset([my_first_time_series,my_second_time_series,my_third_time_series])>>>y=[0,1,1]2. Data preprocessing and transformationsOptionally, tslearn has several utilities to preprocess the data. In order to facilitate the convergence of different algorithms, you canscale time series. Alternatively, in order to speed up training times, one canresamplethe data or apply apiece-wise transformation.>>>fromtslearn.preprocessingimportTimeSeriesScalerMinMax>>>X_scaled=TimeSeriesScalerMinMax().fit_transform(X)>>>print(X_scaled)[[[0.][0.667][1.][0.333][nan]][[0.][0.333][1.][0.333][nan]][[0.][0.333][1.][0.333][0.333]]]3. Training a modelAfter getting the data in the right format, a model can be trained. Depending on the use case, tslearn supports different tasks: classification, clustering and regression. For an extensive overview of possibilities, check out ourgallery of examples.>>>fromtslearn.neighborsimportKNeighborsTimeSeriesClassifier>>>knn=KNeighborsTimeSeriesClassifier(n_neighbors=1)>>>knn.fit(X_scaled,y)>>>print(knn.predict(X_scaled))[011]As can be seen, the models in tslearn follow the same API as those of the well-known scikit-learn. Moreover, they are fully compatible with it, allowing to use different scikit-learn utilities such ashyper-parameter tuning and pipelines.4. More analysestslearn further allows to perform all different types of analysis. Examples includecalculating barycentersof a group of time series or calculate the distances between time series using avariety of distance metrics.Available featuresdataprocessingclusteringclassificationregressionmetricsUCR DatasetsScalingTimeSeriesKMeansKNN ClassifierKNN RegressorDynamic Time WarpingGeneratorsPiecewiseKShapeTimeSeriesSVCTimeSeriesSVRGlobal Alignment KernelConversion(1,2)KernelKmeansLearningShapeletsMLPBarycentersEarly ClassificationMatrix ProfileDocumentationThe documentation is hosted atreadthedocs. It includes anAPI,gallery of examplesand auser guide.ContributingIf you would like to contribute totslearn, please have a look atour contribution guidelines. A list of interesting TODO's can be foundhere.If you want other ML methods for time series to be added to this TODO list, do not hesitate toopen an issue!Referencing tslearnIf you usetslearnin a scientific publication, we would appreciate citations:@article{JMLR:v21:20-091,author={Romain Tavenard and Johann Faouzi and Gilles Vandewiele andFelix Divo and Guillaume Androz and Chester Holtz andMarie Payne and Roman Yurchak and Marc Ru{\ss}wurm andKushal Kolar and Eli Woods},title={Tslearn, A Machine Learning Toolkit for Time Series Data},journal={Journal of Machine Learning Research},year={2020},volume={21},number={118},pages={1-6},url={http://jmlr.org/papers/v21/20-091.html}}AcknowledgmentsAuthors would like to thank Mathieu Blondel for providing code forKernel k-meansandSoft-DTW, and to Mehran Maghoumi for historch-compatible implementation of SoftDTW.