项目作者: BorgwardtLab

项目描述 :
A Wasserstein Subsequence Kernel for Time Series.
高级语言: Python
项目地址: git://github.com/BorgwardtLab/WTK.git
创建时间: 2019-10-08T12:00:51Z
项目社区:https://github.com/BorgwardtLab/WTK

开源协议:MIT License

下载


Wasserstein Time Series Kernel

A preprint version of the paper accepted at ICDM 2019 can be found here.

Dependencies

WTK relies on the following dependencies:

  • numpy
  • scikit-learn
  • POT
  • cython

Installation

The easiest way is to install WTK from the Python Package Index (PyPI) via

  1. $ pip install cython numpy wtk

Usage

The 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.
Additionally, we provide a way to run a grid search for a krein space SVM. krein_svm_grid_search runs a 5-fold
cross-validation on the training set to determine the best hyperparameters. Then, its classification accuracy is
computed on the test set.

  1. from wtk import transform_to_dist_matrix
  2. from wtk.utilities import get_ucr_dataset, krein_svm_grid_search
  3. # Read UCR data
  4. X_train, y_train, X_test, y_test = get_ucr_dataset('../data/UCR/raw_data/', 'DistalPhalanxTW')
  5. # Compute wasserstein distance matrices with subsequence length k=10
  6. D_train, D_test = transform_to_dist_matrix(X_train, X_test, 10)
  7. # Run the grid search
  8. svm_clf = krein_svm_grid_search(D_train, D_test, y_train, y_test)

Alternatively, you can get the kernel matrices computed from the distance matrices and train your own classifier.

  1. from sklearn.svm import SVC
  2. from wtk import get_kernel_matrix
  3. from sklearn.metrics import accuracy_score
  4. from sklearn.svm import SVC
  5. # Get the kernel matrices
  6. K_train = get_kernel_matrix(D_train, psd=True, gamma=0.2)
  7. K_test = get_kernel_matrix(D_test, psd=False, gamma=0.2)
  8. # Train your classifier
  9. clf = SVC(C=5, kernel='precomputed')
  10. clf.fit(K_train, y_train)
  11. y_pred = clf.predict(K_test)
  12. print(accuracy_score(y_test, y_pred))

Examples

You can find some simple examples on our examples
page
and an
examples jupyter
notebook
.
In case the notebook cannot be rendered, please visit it on
nbviewer.

Help

If you have questions concerning WTK or you encounter problems when
trying to build the tool under your own system, please open an issue in
the issue tracker. Try to
describe the issue in sufficient detail in order to make it possible for
us to help you.

Contributors

WTK is developed and maintained by members of the Machine Learning and
Computational Biology Lab
:

Citation

Please use the following BibTeX citation when using our method or comparing to it:

  1. @InProceedings{Bock19,
  2. author = {Bock, Christian and Togninalli, Matteo and Ghisu, Elisabetta and Gumbsch, Thomas and Rieck, Bastian and Borgwardt, Karsten},
  3. title = {A Wasserstein Subsequence Kernel for Time Series},
  4. booktitle = {Proceedings of the 19th IEEE International Conference on Data Mining~(ICDM)},
  5. year = {2019},
  6. pubstate = {inpress},
  7. }