A machine learning interface for sequence classification algorithms in Python.
Project description
Sequentia
A machine learning interface for sequence classification algorithms in Python.
About · Build Status · Features · Documentation · Tutorials and Examples · Acknowledgments · References · Contributors
About
Sequentia is a Python package that provides various classification algorithms for sequential data, including classifiers based on hidden Markov models and dynamic time warping.
Some examples of how Sequentia can be used in sequence classification include:
- determining a spoken word based on its audio signal or alternative representations such as MFCCs,
- identifying heart conditions such as arrhythmia from ECG signals,
- predicting motion intent for gesture control from sEMG signals,
- classifying hand-written characters according to their pen-tip trajectories.
Build Status
master |
dev |
---|---|
Features
Sequentia provides the following algorithms, all supporting multivariate sequences with different durations.
Classification algorithms
- Hidden Markov Models (via
hmmlearn
)
Parameter estimation with the Baum-Welch algorithm and prediction with the forward algorithm [1]- Gaussian Mixture Model emissions
- Linear, left-right and ergodic topologies
- Multi-processed predictions
- Dynamic Time Warping k-Nearest Neighbors (via
dtaidistance
)- Sakoe–Chiba band global warping constraint
- Dependent and independent feature warping (DTWD & DTWI)
- Custom distance-weighted predictions
- Multi-processed predictions
Example of a classification algorithm (HMM sequence classifier)
Preprocessing methods
- Centering, standardization and min-max scaling
- Decimation and mean downsampling
- Mean and median filtering
- Dimensionality reduction (soon!)
Installation
You can install Sequentia using pip
.
pip install sequentia
Click here for installation instructions for contributing to Sequentia or running the notebooks.
If you intend to help contribute to Sequentia, you will need some additional dependencies for running tests, notebooks and generating documentation.
Depending on what you intend to do, you can specify the following extras.
-
For running tests in the
/lib/test
directory:pip install sequentia[test]
-
For generating Sphinx documentation in the
/docs
directory:pip install sequentia[docs]
-
For running notebooks in the
/notebooks
directory:pip install sequentia[notebooks]
-
A full development suite which installs all of the above extras:
pip install sequentia[dev]
Documentation
Documentation for the package is available on Read The Docs.
Tutorials and Examples
For detailed tutorials and examples on the usage of Sequentia, see the notebooks here.
Below are some basic examples of how univariate and multivariate sequences can be used in Sequentia.
Univariate sequences
import numpy as np, sequentia as seq
# Generate training observation sequences and labels
X, y = [
np.array([1, 0, 5, 3, 7, 2, 2, 4, 9, 8, 7]),
np.array([2, 1, 4, 6, 5, 8]),
np.array([5, 8, 0, 3, 1, 0, 2, 7, 9])
], ['good', 'good', 'bad']
# Create and fit the classifier
clf = seq.KNNClassifier(k=1, classes=('good', 'bad')).fit(X, y)
# Make a prediction for a new observation sequence
x_new = np.array([0, 3, 2, 7, 9, 1, 1])
y_new = clf.predict(x_new)
Multivariate sequences
import numpy as np, sequentia as seq
# Generate training observation sequences and labels
X, y = [
np.array([[1, 0, 5, 3, 7, 2, 2, 4, 9, 8, 7],
[3, 8, 4, 0, 7, 1, 1, 3, 4, 2, 9]]).T,
np.array([[2, 1, 4, 6, 5, 8],
[5, 3, 9, 0, 8, 2]]).T,
np.array([[5, 8, 0, 3, 1, 0, 2, 7, 9],
[0, 2, 7, 1, 2, 9, 5, 8, 1]]).T
], ['good', 'good', 'bad']
# Create and fit the classifier
clf = seq.KNNClassifier(k=1, classes=('good', 'bad')).fit(X, y)
# Make a prediction for a new observation sequence
x_new = np.array([[0, 3, 2, 7, 9, 1, 1],
[2, 5, 7, 4, 2, 0, 8]]).T
y_new = clf.predict(x_new)
Acknowledgments
In earlier versions of the package (<0.10.0), an approximate dynamic time warping algorithm implementation (fastdtw
) was used in hopes of speeding up k-NN predictions, as the authors of the original FastDTW paper [2] claim that approximated DTW alignments can be computed in linear memory and time - compared to the O(N^2) runtime complexity of the usual exact DTW implementation.
However, I was recently contacted by Prof. Eamonn Keogh (at University of California, Riverside), whose recent work [3] makes the surprising revelation that FastDTW is generally slower than the exact DTW algorithm that it approximates. Upon switching from the fastdtw
package to dtaidistance
(a very solid implementation of exact DTW with fast pure C compiled functions), DTW k-NN prediction times were indeed reduced drastically.
I would like to thank Prof. Eamonn Keogh for directly reaching out to me regarding this finding!
References
Contributors
All contributions to this repository are greatly appreciated. Contribution guidelines can be found here.
eonu |
Prhmma |
manisci |
---|
Sequentia © 2019-2023, Edwin Onuonga - Released under the MIT License.
Authored and maintained by Edwin Onuonga.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file sequentia-0.13.1.tar.gz
.
File metadata
- Download URL: sequentia-0.13.1.tar.gz
- Upload date:
- Size: 19.6 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5a9995c920d873cc4966aa7a0dd8974df4bf644df035a8b4589e05f2eddf5e78 |
|
MD5 | dd94c3243900df59b48b7f64dc54f8c4 |
|
BLAKE2b-256 | 0e088ffea3be78690b171197a50fca4549754a6343622f218e93903de04a672f |