Skip to main content

A Python package that implements string kernels.

Project description

strkernels

strkernels is a Python package compatible with Scikit-learn that implements string kernels.

String kernels are functions that return a value representing how similar two input strings are. They are widely used in machine learning methods for text and biological sequence analysis.

The prominent aspect of string kernels is that the prior extraction and selection of sequence features are unnecessary. The sample symbol sequences are inputs to the kernel function, automatically finding the distinguishing string features.

Currently, the available string kernels are:

  • Locality Improved (Zien et al. 2000)
  • Subsequence (Lodhi et al. 2002)
  • Spectrum (Leslie et al. 2002)
  • Weighted Degree (Ratsch et al. 2004)
  • Fixed Degree (Sonnenburg et al. 2010)

Basic usage

Install with pip:

pip install strkernels

Import and create a kernel:

from strkernels import SubsequenceStringKernel
subsequence_kernel = SubsequenceStringKernel(maxlen=3, ssk_lambda=0.5)

Example data:

import numpy as np
strings = np.array(["ATCG", "ATGG", "TACG", "GCTA"])
y = np.array([-1, -1, 1, 1])

Compute the kernel matrix:

kernel_matrix = subsequence_kernel(strings, strings)

print(kernel_matrix)
[[1.         0.74037191 0.91640867 0.79256966]
 [0.74037191 1.         0.68420576 0.65356968]
 [0.91640867 0.68420576 1.         0.84210526]
 [0.79256966 0.65356968 0.84210526 1.        ]]

Or use the kernel object with Scikit-learn:

from sklearn.svm import SVC
clf = SVC(kernel=subsequence_kernel)

# train the classifier
clf.fit(strings, y)

# make predictions using the classifier
predictions = clf.predict(strings)

print(predictions)
[-1 -1  1  1]

Documentation

Refer to the documentation for comprehensive examples of applying string kernels to biological sequences.

Reference

If you use or discuss this package, please cite:

Barbosa, D.F., Rocha, M., Kashiwabara, A.Y. (2024). strkernels: a optimized string kernels Python package. Under development.

License

GNU GPLv3

Contact

To report bugs, to ask for help and to give any feedback, please contact denilsonfbar@gmail.com

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

strkernels-0.2.1.tar.gz (23.4 kB view details)

Uploaded Source

Built Distributions

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

strkernels-0.2.1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (121.3 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

strkernels-0.2.1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (121.3 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

strkernels-0.2.1-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (121.3 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

strkernels-0.2.1-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (121.3 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

File details

Details for the file strkernels-0.2.1.tar.gz.

File metadata

  • Download URL: strkernels-0.2.1.tar.gz
  • Upload date:
  • Size: 23.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for strkernels-0.2.1.tar.gz
Algorithm Hash digest
SHA256 a9d7c77da9ceed3f23bab86d93ad99ef4082df5f8a4d362f26e01306328a8cc8
MD5 f25778f6bb2e03c46fe6a7b80315d12a
BLAKE2b-256 54698b0ade9ec45c4795fd07082daf002141d65701ade98c1a8b8e905f8b2df9

See more details on using hashes here.

File details

Details for the file strkernels-0.2.1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for strkernels-0.2.1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 1d201f634fc4bfed91820d420590399b4ffd51d01424649fb2a4f18fdec44166
MD5 024ffa189f133000dc427ceadc37dbf1
BLAKE2b-256 80fad775c27d34a6a2342eebc7c10b2183ec85d8b2fc310863f948d459bbf674

See more details on using hashes here.

File details

Details for the file strkernels-0.2.1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for strkernels-0.2.1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 a14f3f69adc9f7ab435d8a1d85b5402de633578f9d06eda206c1aa88c001c7ff
MD5 dec55a1987e539d0140787b57311a285
BLAKE2b-256 fa55e1fd70cd8e7018c3674edf3ffd29d5662aa8300fa6ced4d8a2e62d1e9123

See more details on using hashes here.

File details

Details for the file strkernels-0.2.1-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for strkernels-0.2.1-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 df9504e7a9fa58968d14ded6428a48110e6b092dc4cd32c82f7ae34638502b51
MD5 58a84bd99394e335e446bb2f1ca15888
BLAKE2b-256 082233b1bd0703ffd3b0cd28c24a38e7c11c165c35f2cbe8f2b5af7550cba132

See more details on using hashes here.

File details

Details for the file strkernels-0.2.1-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for strkernels-0.2.1-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 5c6a657b5671e8f65cc7af435111bc721e274e7169ec3841095d27a2bdc96c9c
MD5 ed2810bc8572f116776a0a9fb1ea3502
BLAKE2b-256 d5a015c60296a5c27a94aa649420a0f4900684758a939aba0783003e6d99aeca

See more details on using hashes here.

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