{"id":21280586,"url":"https://github.com/borgwardtlab/wtk","last_synced_at":"2025-07-11T10:32:21.842Z","repository":{"id":37702752,"uuid":"213630349","full_name":"BorgwardtLab/WTK","owner":"BorgwardtLab","description":"A Wasserstein Subsequence Kernel for Time Series.","archived":false,"fork":false,"pushed_at":"2024-06-17T23:06:46.000Z","size":213,"stargazers_count":21,"open_issues_count":1,"forks_count":7,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-11-08T15:05:26.300Z","etag":null,"topics":["data-mining","machine-learning","optimal-transport","time-series-classification"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BorgwardtLab.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-10-08T12:00:51.000Z","updated_at":"2024-04-30T05:55:49.000Z","dependencies_parsed_at":"2022-09-04T04:10:14.391Z","dependency_job_id":null,"html_url":"https://github.com/BorgwardtLab/WTK","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BorgwardtLab%2FWTK","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BorgwardtLab%2FWTK/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BorgwardtLab%2FWTK/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BorgwardtLab%2FWTK/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BorgwardtLab","download_url":"https://codeload.github.com/BorgwardtLab/WTK/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225715470,"owners_count":17512902,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["data-mining","machine-learning","optimal-transport","time-series-classification"],"created_at":"2024-11-21T10:37:13.397Z","updated_at":"2024-11-21T10:37:13.921Z","avatar_url":"https://github.com/BorgwardtLab.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Wasserstein Time Series Kernel\nA preprint version of the paper accepted at ICDM 2019 can be found [here](https://christian.bock.ml/publications/ICDM2019_WTK.pdf).\n\n## Dependencies\n\nWTK relies on the following dependencies:\n\n- `numpy`\n- `scikit-learn`\n- `POT`\n- `cython`\n\n## Installation\n\nThe easiest way is to install WTK from the Python Package Index (PyPI) via\n\n```\n$ pip install cython numpy wtk\n```\n\n## Usage\nThe package provides functions to transform a set of `n` training time series and `o` test time series into an `n x n` distance matrix for training and an `o x n` distance matrix for testing.\nAdditionally, we provide a way to run a grid search for a krein space SVM. `krein_svm_grid_search` runs a `5`-fold\ncross-validation on the training set to determine the best hyperparameters. Then, its classification accuracy is\ncomputed on the test set.\n\n```python\nfrom wtk import transform_to_dist_matrix\nfrom wtk.utilities import get_ucr_dataset, krein_svm_grid_search\n\n# Read UCR data\nX_train, y_train, X_test, y_test = get_ucr_dataset('../data/UCR/raw_data/', 'DistalPhalanxTW')\n\n# Compute wasserstein distance matrices with subsequence length k=10\nD_train, D_test = transform_to_dist_matrix(X_train, X_test, 10)\n\n# Run the grid search\nsvm_clf = krein_svm_grid_search(D_train, D_test, y_train, y_test)\n```\n\nAlternatively, you can get the kernel matrices computed from the distance matrices and train your own classifier.\n\n```python\nfrom sklearn.svm import SVC\nfrom wtk import get_kernel_matrix\nfrom sklearn.metrics import accuracy_score\nfrom sklearn.svm import SVC\n\n# Get the kernel matrices\nK_train = get_kernel_matrix(D_train, psd=True, gamma=0.2)\nK_test = get_kernel_matrix(D_test, psd=False, gamma=0.2)\n\n# Train your classifier\nclf = SVC(C=5, kernel='precomputed')\nclf.fit(K_train, y_train)\n\ny_pred = clf.predict(K_test)\nprint(accuracy_score(y_test, y_pred))\n```\n\n## Examples\n\nYou can find some simple examples on our [examples\npage](https://github.com/BorgwardtLab/WTK/tree/master/examples) and an\nexamples [jupyter\nnotebook](https://github.com/BorgwardtLab/WTK/blob/master/examples/example_notebook.ipynb).\nIn case the notebook cannot be rendered, please visit it on\n[nbviewer](https://nbviewer.jupyter.org/github/BorgwardtLab/WTK/blob/master/examples/example_notebook.ipynb).\n\n## Help\n\nIf you have questions concerning WTK or you encounter problems when\ntrying to build the tool under your own system, please open an issue in\n[the issue tracker](https://github.com/BorgwardtLab/WTK/issues). Try to\ndescribe the issue in sufficient detail in order to make it possible for\nus to help you.\n\n## Contributors\n\nWTK is developed and maintained by members of the [Machine Learning and\nComputational Biology Lab](https://www.bsse.ethz.ch/mlcb):\n\n- Christian Bock ([GitHub](https://github.com/chrisby))\n- Matteo Togninalli ([GitHub](https://github.com/mtog))\n- Bastian Rieck ([GitHub](https://github.com/Pseudomanifold))\n\n## Citation\nPlease use the following BibTeX citation when using our method or comparing to it:\n```\n@InProceedings{Bock19,\n  author    = {Bock, Christian and Togninalli, Matteo and Ghisu, Elisabetta and Gumbsch, Thomas and Rieck, Bastian and Borgwardt, Karsten},\n  title     = {A Wasserstein Subsequence Kernel for Time Series},\n  booktitle = {Proceedings of the 19th IEEE International Conference on Data Mining~(ICDM)},\n  year      = {2019},\n  pubstate  = {inpress},\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fborgwardtlab%2Fwtk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fborgwardtlab%2Fwtk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fborgwardtlab%2Fwtk/lists"}