Python implementation of the Learning Time-Series Shapelets method, that learns a shapelet-based time-series classifier with gradient descent.

Overview

shaplets

Python implementation of the Learning Time-Series Shapelets method by Josif Grabocka et al., that learns a shapelet-based time-series classifier with gradient descent.

This implementation views the model as a layered graph, where each layer implements a forward, backword and parameters update methods (see below diagram). This abstraction simplifies thinking about the algorithm and implementing it. Network diagram

Differences from the paper

  • This implmenetation employs two (LinearLayer + SigmoidLayer) pairs instead of one (LinearLayer + SigmoidLayer) pair as in the paper (and shown in above diagram). This (using two pairs) has yielded improved results on some datasets. To have a similar setup as in the paper, simply update shapelets_lts/classification/shapelet_models.py:LtsShapeletClassifier._init_network().
  • The loss in this implementation is an updated version of the one in the paper to allow training a single model for all the classes in the dataset (rather than one model/class). The impact on performance was not analysed. For details check shapelets_lts/network/cross_entropy_loss_layer.py

Installation

git clone [email protected]:mohaseeb/shaplets-python.git
cd shaplets-python
pip install .
# or, for dev
# pip install .[dev]

Usage

from shapelets_lts.classification import LtsShapeletClassifier

# create an LtsShapeletClassifier instance
classifier = LtsShapeletClassifier(
    K=20,
    R=3,
    L_min=30,
    epocs=50,
    lamda=0.01,
    eta=0.01,
    shapelet_initialization='segments_centroids',
    plot_loss=True
)

# train the classifier. 
# train_data.shape -> (# train samples X time-series length) 
# train_label.shape -> (# train samples)
classifier.fit(train_data, train_label, plot_loss=True)

# evaluate on test data. 
# test_data.shape -> (# test samples X time-series length)
prediction = classifier.predict(test_data)

# retrieve the learnt shapelets
shapelets = classifier.get_shapelets()


# and plot sample shapelets
from shapelets_lts.util import plot_sample_shapelets
plot_sample_shapelets(shapelets=shapelets, sample_size=36)

Also have a look at example.py. For a stable training, the samples might need to be scaled.

Example plot from plot_sample_shapelets. sample_shapelets

Comments
  • Prediction accuracy for example.py

    Prediction accuracy for example.py

    Hello,

    I have ran example.py multiple times (200 epoch for training) for the GUN_point data set. I standardized the training/test data, and changed the code make sure it outputs a prediction label of 0 or 1.

    But I can only get an accuracy of around 75%. Am I missing anything?

    opened by zwang4 5
  • can be your code used for multivariate time series prediction ?

    can be your code used for multivariate time series prediction ?

    great code thanks only can you clarify if can be your code used for multivariate time series prediction like https://github.com/alan-turing-institute/sktime/blob/master/examples/multivariate_time_series_classification.ipynb

    opened by Sandy4321 3
  • Algorithm fails when time series is not scaled

    Algorithm fails when time series is not scaled

    Hi,

    When I try to run the algorithm on my timeseries dataset which contains raw numbers, I get the below warning: line 67 in soft_min_layer.py *** RuntimeWarning: invalid value encountered in double_scalars

    I believe its because negative exponential of large number is converted to zero when using numpy's exponent method. As I do not prefer to scale the data, is there any other work around ?

    I tried to replace numpy's exp with mpmath's exp method, but I still get the same warning.

    opened by rsravan91 3
  • Using Shapelets Just for Feature Extraction

    Using Shapelets Just for Feature Extraction

    Great work on this library by the way! I am writing to inquire about how I could best apply shapelet transformation to my use case. If I simply wanted to get the transformed shaplets features on a multivariate time series (cross sectional/panel data), what would I do? What I think I would like to do is to do a shapelet transformation to generate features from a time series to then feed in a keras deep neural network for traditional binary classification. Does this sound advisable to you or would you recommend a different approach? Thanks again, John

    opened by smrtslckr 2
  • availablity of  shapelet clustering

    availablity of shapelet clustering

    hi there,

    thanks for sharing the implementation, is it possible to provide the implementation of shapelet clustering in addition to classification?

    best,

    pandaa

    opened by texaspandaa 1
  • will it work for multivariate time series prediction   both regression and classification

    will it work for multivariate time series prediction both regression and classification

    great code thanks may you clarify : will it work for multivariate time series prediction both regression and classification 1 where all values are continues values weight height age target 1 56 160 34 1.2 2 77 170 54 3.5 3 87 167 43 0.7 4 55 198 72 0.5 5 88 176 32 2.3

    2 or even will it work for multivariate time series where values are mixture of continues and categorical values for example 2 dimensions have continues values and 3 dimensions are categorical values

    color        weight     gender  height  age  target 
    

    1 black 56 m 160 34 yes 2 white 77 f 170 54 no 3 yellow 87 m 167 43 yes 4 white 55 m 198 72 no 5 white 88 f 176 32 yes

    opened by Sandy4321 0
  • Normalizing the dataset results in a single class prediction

    Normalizing the dataset results in a single class prediction

    I have used your implementation on my own dataset. It seems to work fine when the data is in its original format. However, whenever I normalize or standardize the data, it always predicts only one class (0 in my case), i.e., all the predictions are 0. I cannot seem to understand why is that. Do you have any idea?

    opened by faaizuddin 0
Owner
Mohamed Haseeb
Mohamed Haseeb
A new mini-batch framework for optimal transport in deep generative models, deep domain adaptation, approximate Bayesian computation, color transfer, and gradient flow.

BoMb-OT Python3 implementation of the papers On Transportation of Mini-batches: A Hierarchical Approach and Improving Mini-batch Optimal Transport via

Khai Ba Nguyen 18 Nov 14, 2022
Implementation of the Angular Spectrum method in Python to simulate Diffraction Patterns

Diffraction Simulations - Angular Spectrum Method Implementation of the Angular Spectrum method in Python to simulate Diffraction Patterns with arbitr

Rafael de la Fuente 276 Dec 30, 2022
Python implementation of the ASFLIP advection method

This is a python implementation of the ASFLIP advection method . We would like to hear from you if you appreciate this work.

Raymond Yun Fei 133 Nov 13, 2022
Extract gene length based on featureCount calculation gene nonredundant exon length method.

Extract gene length based on featureCount calculation gene nonredundant exon length method.

laojunjun 12 Nov 21, 2022
Batch obfuscator based on the obfuscation method used by the trick bot launcher

Batch obfuscator based on the obfuscation method used by the trick bot launcher

SlizBinksman 2 Mar 19, 2022
Implementation of the MDMC method to search for magnetic ground state using VASP

Implementation of MDMC method ( by Olga Vekilova ) to search for magnetic ground state using VASP

Utkarsh Singh 1 Nov 27, 2021
Python meta class and abstract method library with restrictions.

abcmeta Python meta class and abstract method library with restrictions. This library provides a restricted way to validate abstract methods. The Pyth

Morteza NourelahiAlamdari 8 Dec 14, 2022
Lagrange Interpolation Method-Python

Lagrange Interpolation Method-Python The Lagrange interpolation formula is a way to find a polynomial, called Lagrange polynomial, that takes on certa

Motahare Soltani 2 Jul 5, 2022
A python package to adjust the bias of probabilistic forecasts/hindcasts using "Mean and Variance Adjustment" method.

Documentation A python package to adjust the bias of probabilistic forecasts/hindcasts using "Mean and Variance Adjustment" method. Read documentation

null 1 Feb 2, 2022
This is a method to build your own qgis configuration packages using osgeo4W.

This is a method to build your own qgis configuration packages using osgeo4W. Then you can automate deployment in your organization with a controled and trusted environnement.

Régis Haubourg 26 Dec 5, 2022
tetrados is a tool to generate a density of states using the linear tetrahedron method from a band structure.

tetrados tetrados is a tool to generate a density of states using the linear tetrahedron method from a band structure. Currently, only VASP calculatio

Alex Ganose 1 Dec 21, 2021
A simple method to create strong password.

A simple method to create strong password.

null 1 Jan 23, 2022
AHP Calculator - A method for organizing and evaluating complicated decisions, using Maths and Psychology

AHP Calculator - A method for organizing and evaluating complicated decisions, using Maths and Psychology

null 16 Aug 8, 2022
OnTime is a small python that you set a time and on that time, app will send you notification and also play an alarm.

OnTime Always be OnTime! What is OnTime? OnTime is a small python that you set a time and on that time, app will send you notification and also play a

AmirHossein Mohammadi 11 Jan 16, 2022
Unofficial Python Library to communicate with SESAME 3 series products from CANDY HOUSE, Inc.

pysesame3 Unofficial Python Library to communicate with SESAME 3 series products from CANDY HOUSE, Inc. This project aims to control SESAME 3 series d

Masaki Tagawa 18 Dec 12, 2022
An open-source Python project series where beginners can contribute and practice coding.

Python Mini Projects A collection of easy Python small projects to help you improve your programming skills. Table Of Contents Aim Of The Project Cont

Leah Nguyen 491 Jan 4, 2023
A Python script to convert your favorite TV series into an Anki deck.

Ankiniser A Python3.8 script to convert your favorite TV series into an Anki deck. How to install? Download the script with git or download it manualy

null 37 Nov 3, 2022
A series of basic programs written in Python

Primeros programas en Python Una serie de programas básicos escritos en Python

Madirex 1 Feb 15, 2022
Python Create Your Own Tool Series

Python Create Your Own Tool Series Hey there! This is an additional Github repository that contains the final product files for each video in my Youtu

Joe Helle 21 Dec 2, 2022