Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gbtsvm-0.0.4.tar.gz (38.8 kB view details)

Uploaded Source

Built Distribution

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

gbtsvm-0.0.4-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file gbtsvm-0.0.4.tar.gz.

File metadata

  • Download URL: gbtsvm-0.0.4.tar.gz
  • Upload date:
  • Size: 38.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for gbtsvm-0.0.4.tar.gz
Algorithm Hash digest
SHA256 74337337c172366123bc15b0bfb3e6ad9b3c6155b2af94c320c88fec56892cb4
MD5 9c6f0e97e891e7c5717e6f7d9592b80f
BLAKE2b-256 c01f29c88037c1578f50c3ba323a9a82be7b6d774bbc4ea1018d2ac5373d1c21

See more details on using hashes here.

File details

Details for the file gbtsvm-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: gbtsvm-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 8.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for gbtsvm-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 b5eb9130521e80869679c72daff9d1df8813a531427bca38e13e5a052a38ad77
MD5 bbbdaa62dc9206dfd33f9a3ce93caddf
BLAKE2b-256 3f00ba3b59e1b600bc95fe1fc402c344342457f2549b72ae13f1230f0beb96b8

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