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
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
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
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file strkernels-0.2.15.tar.gz.
File metadata
- Download URL: strkernels-0.2.15.tar.gz
- Upload date:
- Size: 25.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d83afc8a48fca8a9137f2fa697dc7395d03657835816b0103011b14f58ad5508
|
|
| MD5 |
04c09b37c35a892a493743bcbf16fc6b
|
|
| BLAKE2b-256 |
94c8c11031a735fe8f2bf89655704bcd0fe859a3d04a6137ebc767aaf4a0f76d
|
File details
Details for the file strkernels-0.2.15-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: strkernels-0.2.15-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 129.3 kB
- Tags: CPython 3.13, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6d93b6b77771b1389637a6ef6ba9aa6fb4df73fb80e025daba833bf4bdc8957a
|
|
| MD5 |
f6c2d5f57554d7738cb80cac1c0ead0b
|
|
| BLAKE2b-256 |
2cadcd7c6c44f8e9c2b4c188abb2566c2359fdbde8cbc1c1663781691674c8b5
|
File details
Details for the file strkernels-0.2.15-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: strkernels-0.2.15-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 129.3 kB
- Tags: CPython 3.12, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
02a3faa75c0f902187ca4dba3832911e6241295e97dc2627285a1cbe93635f28
|
|
| MD5 |
5d8556b4e3a84a2ea7e5ce21a2a5db3d
|
|
| BLAKE2b-256 |
e2efc559d36d55d42502496f7c5ebef375bf05e262273334747354ac497b1227
|
File details
Details for the file strkernels-0.2.15-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: strkernels-0.2.15-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 129.2 kB
- Tags: CPython 3.11, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
78d2715684264abebb1f4d3d70164dcbdc96bbd5241bff0aa39fa9b382e8432e
|
|
| MD5 |
23a4523f9603d06fe4371a6054811ed5
|
|
| BLAKE2b-256 |
479175a68ef8b3967dcc65d255205ab19ffcfd832fc115853b2c8c70d4d82968
|
File details
Details for the file strkernels-0.2.15-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: strkernels-0.2.15-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 129.2 kB
- Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
70c8e3151fe44f97851eae1e80e95bf76ffc0229e0fec17e041ea8c0e26f2934
|
|
| MD5 |
551c2c861efe14acd27b76471c9418dd
|
|
| BLAKE2b-256 |
f5a7611a8c89e8a24f2cdf382ac8852794dff9865412ec87afbde8f80acd72c5
|
File details
Details for the file strkernels-0.2.15-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: strkernels-0.2.15-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 129.2 kB
- Tags: CPython 3.9, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d241974658f7ca04cd1299847af1db0e7864f030a94663533c75ccb1dbed4df8
|
|
| MD5 |
3f27ba1b66ee87641a03728040690de8
|
|
| BLAKE2b-256 |
1b24e8e152489c9a200d8f80fb2cf281dd0918b96881db0242c9bd967efd6024
|