{"id":13528727,"url":"https://github.com/mohaseeb/shaplets-python","last_synced_at":"2025-04-01T14:32:53.972Z","repository":{"id":46659051,"uuid":"61485056","full_name":"mohaseeb/shaplets-python","owner":"mohaseeb","description":"Python implementation of the Learning Time-Series Shapelets method, that learns a shapelet-based time-series classifier with gradient descent.","archived":false,"fork":false,"pushed_at":"2019-11-09T07:59:49.000Z","size":376,"stargazers_count":218,"open_issues_count":2,"forks_count":59,"subscribers_count":12,"default_branch":"master","last_synced_at":"2024-11-02T15:36:14.022Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mohaseeb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-06-19T14:49:51.000Z","updated_at":"2024-10-15T12:25:23.000Z","dependencies_parsed_at":"2022-07-20T08:17:24.112Z","dependency_job_id":null,"html_url":"https://github.com/mohaseeb/shaplets-python","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/mohaseeb%2Fshaplets-python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mohaseeb%2Fshaplets-python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mohaseeb%2Fshaplets-python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mohaseeb%2Fshaplets-python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mohaseeb","download_url":"https://codeload.github.com/mohaseeb/shaplets-python/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246655230,"owners_count":20812603,"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":[],"created_at":"2024-08-01T07:00:23.370Z","updated_at":"2025-04-01T14:32:53.115Z","avatar_url":"https://github.com/mohaseeb.png","language":"Python","readme":"# shaplets\nPython implementation of [the Learning Time-Series Shapelets method by Josif Grabocka et al.](http://www.ismll.uni-hildesheim.de/pub/pdfs/grabocka2014e-kdd.pdf), that learns a shapelet-based time-series classifier with gradient descent. \n\nThis implementation views the model as a layered graph, where each layer \nimplements a forward, backword and parameters update methods (see below \ndiagram). This abstraction simplifies thinking about the algorithm and implementing it.\n![Network diagram](lts-diag.png)\n\n## Differences from the paper ##\n* 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()`. \n* The loss in this implementation is an updated version of the one in the \npaper 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`\n\n## Installation ##\n```bash\ngit clone git@github.com:mohaseeb/shaplets-python.git\ncd shaplets-python\npip install .\n# or, for dev\n# pip install .[dev]\n```\n## Usage ##\n```python\nfrom shapelets_lts.classification import LtsShapeletClassifier\n\n# create an LtsShapeletClassifier instance\nclassifier = LtsShapeletClassifier(\n    K=20,\n    R=3,\n    L_min=30,\n    epocs=50,\n    lamda=0.01,\n    eta=0.01,\n    shapelet_initialization='segments_centroids',\n    plot_loss=True\n)\n\n# train the classifier. \n# train_data.shape -\u003e (# train samples X time-series length) \n# train_label.shape -\u003e (# train samples)\nclassifier.fit(train_data, train_label, plot_loss=True)\n\n# evaluate on test data. \n# test_data.shape -\u003e (# test samples X time-series length)\nprediction = classifier.predict(test_data)\n\n# retrieve the learnt shapelets\nshapelets = classifier.get_shapelets()\n\n\n# and plot sample shapelets\nfrom shapelets_lts.util import plot_sample_shapelets\nplot_sample_shapelets(shapelets=shapelets, sample_size=36)\n```\nAlso have a look at example.py. For a stable training, the samples might need to be scaled.\n\nExample plot from plot_sample_shapelets.\n![sample_shapelets](sample_shapelets.png)\n","funding_links":[],"categories":["Examples or singular models"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmohaseeb%2Fshaplets-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmohaseeb%2Fshaplets-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmohaseeb%2Fshaplets-python/lists"}