Skip to main content

A napari plugin that classifies annotated signals stored in a table in the .features of a Labels layer using scikit-learn RandomForest classifier.

Project description

napari-signal-classifier

License BSD-3 PyPI Python Version tests codecov napari hub

A napari plugin that classifies annotated signals stored in a table in the .features of a Labels layer using scikit-learn RandomForest classifier.

It also provides a sub-signal classifier that can be used to classify sub-signals inside time-series. First it detects sub-sginals with a template matching algorithm and then classifies them also using scikit-learn RandomForest classifier.

This plugin employs and works in synergy with the napari-signal-selector plugin. Take a look at it to see how to annotate signals in a plotter linked to a napari Labels layer with the .features attribute.

Usage

Napari Signal Classifier

After having annotated signals in the .features of a Labels layer (check the napari-signal-selector plugin), you can train a signal classifier and predict the labels of unannotated signals.

Open the "Signal Classifier Widget" from the napari in "Layers > Classify > Signal / Time-series > Train and Predict Signal Classifier". The widget will appear in the right panel of napari.

Choose the Labels layer containing the annotated signals to classify (the annotations should have been previsouly done with the napari-signal-selector plugin). Choose the classifier (currently only RandomForest is implemented). Optionally provide a path to a folder where to save the trained model, select the number of trees (estimators) of the RandomForest, the random state for reproducibility, and the training percentage (the percentage of annotated signals that will be used for training, the rest will be used for testing the model and showing the accuracy, intially 80%). Finally click on "Train and Predict".

Several signal features will be calculated automatically from the signals in the .features of the Labels layer, a RandomForest classifier will be trained on the annotated signals, and the labels of unannotated signals will be predicted. The predicted labels will be stored in a new column in the .features of the Labels layer called "Predictions". The accuracy of the model on the test set will be printed in the napari console.

demo

The resulting .features table can be viewed via the native napari features table widget ("Layers > Visualize > Features Table Widget") and exported to a CSV file from there for further analysis.

Napari Sub-Signal Classifier

After having annotated signals in the .features of a Labels layer (check the napari-signal-selector plugin), you can train a sub-signal classifier to classify sub-signals inside time-series.

Open the "Sub-Signal Classifier Widget" from the napari in "Layers > Classify > Signal / Time-series > Train and Predict Sub-Signal Classifier". The widget will appear in the right panel of napari.

Choose the same parameters as the Signal Classifier Widget, plus a few additional parameters related to sub-signal detection and merging: the detection threshold for the template matching algorithm (default 0.8), the detrend option (default False) and smooth factor (default 0) for the template generation and the merging overlap threshold (default 0.5) for merging overlapping detected sub-signals. Finally click on "Train and Predict".

A signal template for each class will be generated by the median sub-signal of annotated sub-signals and a cross-correlation based template matching algorithm will be used to detect sub-signals in unannotated time-series. Several signal features will be calculated automatically from the detected sub-signals, a RandomForest classifier will be trained on the annotated sub-signals, and the detected unannotated sub-signals will be predicted. The predicted labels will be stored in a new column in the .features of the Labels layer called "Predictions". The accuracy of the model on the test set will be printed in the napari console.

demo

Again, the resulting .features table can be viewed via the native napari features table widget ("Layers > Visualize > Features Table Widget") and exported to a CSV file from there for further analysis.


This napari plugin was generated with Cookiecutter using @napari's cookiecutter-napari-plugin template.

Installation

You can install napari-signal-classifier via pip:

pip install napari-signal-classifier

To install latest development version :

pip install git+https://github.com/zoccoler/napari-signal-classifier.git

Contributing

Contributions are very welcome. Tests can be run with tox, please ensure the coverage at least stays the same before you submit a pull request.

License

Distributed under the terms of the BSD-3 license, "napari-signal-classifier" is free and open source software

Issues

If you encounter any problems, please file an issue along with a detailed description.

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

napari_signal_classifier-0.0.1.tar.gz (5.4 MB view details)

Uploaded Source

Built Distribution

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

napari_signal_classifier-0.0.1-py3-none-any.whl (34.4 kB view details)

Uploaded Python 3

File details

Details for the file napari_signal_classifier-0.0.1.tar.gz.

File metadata

  • Download URL: napari_signal_classifier-0.0.1.tar.gz
  • Upload date:
  • Size: 5.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for napari_signal_classifier-0.0.1.tar.gz
Algorithm Hash digest
SHA256 6f9da27f298b6f467452136d06a7e1b28c06c6e668d0e87cb2b8e9dfe8b64e5d
MD5 1d96ef88a4a83c529e2ad4eaa23221ab
BLAKE2b-256 a3d5f7c69b08bad4fc3b2b56ff65a8c4e9c9fbd76eaa69fdc5d2c7d04fa89ea9

See more details on using hashes here.

Provenance

The following attestation bundles were made for napari_signal_classifier-0.0.1.tar.gz:

Publisher: test_and_deploy.yml on zoccoler/napari-signal-classifier

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file napari_signal_classifier-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for napari_signal_classifier-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 892d124dfe338b6444dd9aa2b61b6f1e3529798ac5f4f079ea2cbb2a97aab4d1
MD5 7fa0581ecd3d6a8f7ee373df54a4489a
BLAKE2b-256 a32cc8cd29da77a5d3a5cfe6e6918df6dc9beb10bed827694e00afbc8d2df1d9

See more details on using hashes here.

Provenance

The following attestation bundles were made for napari_signal_classifier-0.0.1-py3-none-any.whl:

Publisher: test_and_deploy.yml on zoccoler/napari-signal-classifier

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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