Granular Ball Twin Support Vector Machine - scikit-learn compatible implementation
Project description
GBTSVM: Granular Ball Twin Support Vector Machine
A scikit-learn compatible implementation of the Granular Ball Twin Support Vector Machine (GBTSVM).
Reference
If you use this code, please cite:
A. Quadir, M. Sajid and M. Tanveer, "Granular Ball Twin Support Vector Machine," in IEEE Transactions on Neural Networks and Learning Systems, vol. 36, no. 7, pp. 12444-12453, July 2025, doi: 10.1109/TNNLS.2024.3476391.
Some parts of this implementation are based on:
Xia, Shuyin, et al. "Gbsvm: Granular-ball support vector machine." arXiv preprint arXiv:2210.03120 (2022).
Installation
# Install with uv (recommended)
uv sync
# Or install with pip
pip install -e .
Usage
import numpy as np
from gbtsvm import GBTSVMClassifier
# Create sample data
X = np.array([[1, 2], [3, 4], [5, 6], [7, 8], [2, 3], [4, 5]])
y = np.array([1, 1, 1, -1, -1, -1])
# Create and fit the classifier
clf = GBTSVMClassifier(c1=0.00001, c2=0.00001)
clf.fit(X, y)
# Make predictions
predictions = clf.predict([[2, 3], [6, 7]])
print(predictions) # Output: [1, -1]
# Get decision function
decision = clf.decision_function([[2, 3], [6, 7]])
print(decision) # Positive = class 1, Negative = class -1
# Evaluate accuracy
accuracy = clf.score(X, y)
print(f"Accuracy: {accuracy:.2f}")
Parameters
c1(float): Regularization parameter for first QPP (default: 1.0)c2(float): Regularization parameter for second QPP (default: 1.0)purity(float): Purity threshold for granular ball generation (default: 0.925)min_samples(int): Minimum samples to keep a granular ball (default: 4)eps1(float): Regularization for numerical stability in first QPP (default: 0.05)eps2(float): Regularization for numerical stability in second QPP (default: 0.05)
Development
# Install with dev dependencies
uv sync --extra dev
# Run tests
make test
# Run linting
make lint
# Run all checks
make check
License
MIT License
Acknowledgments
This implementation is based on the GBTSVM algorithm described in the papers cited above. The original code was not available under an open source license, so this is an independent implementation following the algorithm description in the papers.
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
Built Distribution
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 gbtsvm-0.0.3.tar.gz.
File metadata
- Download URL: gbtsvm-0.0.3.tar.gz
- Upload date:
- Size: 38.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c9f1c55ce1d866a3c6fc8958782a9dcbf84c0daedb0d7a3673a83575c9ba430f
|
|
| MD5 |
8102f59d1c67550fad495e5583c7de30
|
|
| BLAKE2b-256 |
d31edbd350c067eecf7398a31e2cb183f3099faca82dda2e29b63bd2669e7da7
|
File details
Details for the file gbtsvm-0.0.3-py3-none-any.whl.
File metadata
- Download URL: gbtsvm-0.0.3-py3-none-any.whl
- Upload date:
- Size: 8.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
485c48031339ed108a9592b39e956bb7a6e7311e85a995ace4abfff195727b6f
|
|
| MD5 |
dd4ba3f74839a840c5a73eab8c3c48aa
|
|
| BLAKE2b-256 |
4d6e1764df5f41edf8956b74f75039489f67ed92b26108332667d36f2c98aeb3
|