Skip to main content

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.

Metadata

Release files for gbtsvm 0.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gbtsvm 0.0.4
File Size Uploaded
gbtsvm-0.0.4.tar.gz 38.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for gbtsvm 0.0.4
File Interpreter ABI Platform
gbtsvm-0.0.4-py3-none-any.whl Python 3 none any Details

Total release size: 47.6 kB

Release files / gbtsvm-0.0.4.tar.gz

Download URL gbtsvm-0.0.4.tar.gz
Size 38.8 kB
Tags Source
SHA-256 checksum
How to use checksums
74337337c172366123bc15b0bfb3e6ad9b3c6155b2af94c320c88fec56892cb4
BLAKE2b-256 checksum
How to use checksums
c01f29c88037c1578f50c3ba323a9a82be7b6d774bbc4ea1018d2ac5373d1c21
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Release files / gbtsvm-0.0.4-py3-none-any.whl

Download URL gbtsvm-0.0.4-py3-none-any.whl
Size 8.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b5eb9130521e80869679c72daff9d1df8813a531427bca38e13e5a052a38ad77
BLAKE2b-256 checksum
How to use checksums
3f00ba3b59e1b600bc95fe1fc402c344342457f2549b72ae13f1230f0beb96b8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Release history Release notifications | RSS feed

This release

0.0.4 This release

2 release files

0.0.3

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page