Skip to main content

A Wasserstein Subsequence Kernel for Time Series

Project description

Wasserstein Time Series Kernel

Installation

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

$ pip install 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.

from wtk import transform_to_dist_matrix
from wtk.utilities import get_ucr_dataset, krein_svm_grid_search

# Read UCR data
X_train, y_train, X_test, y_test = get_ucr_dataset('../data/UCR/raw_data/', 'DistalPhalanxTW')

# Compute wasserstein distance matrices with subsequent length k=10
D_train, D_test = transform_to_dist_matrix(X_train, X_test, 10)

# Run the grid search
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.

from sklearn.svm import SVC
from wtk import get_kernel_matrix
from sklearn.metrics import accuracy_score

# Get the kernel matrices
K_train = get_kernel_matrix(D_train, psd=True, gamma=0.2)
K_test = get_kernel_matrix(D_test, psd=False, gamma=0.2)

# Train your classifier
clf = SVC(C=5, kernel='precomputed')
clf.fit(K_train, y_train)

y_pred = clf.predict(K_test)
print(accuracy_score(y_test, y_pred))

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 of Prof. Dr. Karsten Borgwardt:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wtk-0.2.1.3.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

wtk-0.2.1.3-py3-none-any.whl (18.3 kB view details)

Uploaded Python 3

File details

Details for the file wtk-0.2.1.3.tar.gz.

File metadata

  • Download URL: wtk-0.2.1.3.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.22.0

File hashes

Hashes for wtk-0.2.1.3.tar.gz
Algorithm Hash digest
SHA256 f5314ed315fd97d1de2ac05f995364971a73e65b878faec5deaabe8484d2ebb6
MD5 5079bf12e0cb6c91f0298a370497a5c1
BLAKE2b-256 54b93f7c48e8a621a2ce79125e070fdfd30cd8de42882fe4b230356a9346e190

See more details on using hashes here.

File details

Details for the file wtk-0.2.1.3-py3-none-any.whl.

File metadata

  • Download URL: wtk-0.2.1.3-py3-none-any.whl
  • Upload date:
  • Size: 18.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.22.0

File hashes

Hashes for wtk-0.2.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 8b73ea9154f3be39734518b766642fdae3e0b273a86eb0298e2eee0f28d1d72f
MD5 a42ddbb82395729e7940d61d3fe5c878
BLAKE2b-256 28857043dde5f14f8c9080767839d6f4a521907f24b6f05e5d01d2e1320fa231

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page