Skip to main content

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:

Metadata

Release files for wtk 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for wtk 0.2.1
File Size Uploaded
wtk-0.2.1.tar.gz 6.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for wtk 0.2.1
File Interpreter ABI Platform
wtk-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 27.1 kB

Release files / wtk-0.2.1.tar.gz

Download URL wtk-0.2.1.tar.gz
Size 6.8 kB
Tags Source
SHA-256 checksum
How to use checksums
55726ad0750780ef5eec30a9f19be874fbf3e6c9c408c809ed212182db654ff8
BLAKE2b-256 checksum
How to use checksums
fec4df0606f3992de872cad5a6ad4c3d60a329263ecc8a35ab24d4d608c5e9c5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.22.0

Release files / wtk-0.2.1-py3-none-any.whl

Download URL wtk-0.2.1-py3-none-any.whl
Size 20.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dc39bf1b262bc59bb238b71423b14d95248a930420008ba10bbe4fa0b7e59dfc
BLAKE2b-256 checksum
How to use checksums
bc8df40ee25c9b6a36023312de79fba0e8cfd42f68e1a28badebe84336fb558a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.22.0

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files

0.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page