Skip to main content

Uncalibrated Linearsvc

Project description

uncalibrated-linearsvc

CI

uncalibrated-linearsvc provides a small scikit-learn-compatible wrapper around sklearn.svm.LinearSVC that adds a predict_proba() method.

What It Is

The package exposes LinearSVCWithUncalibratedProbabilities, a subclass of LinearSVC. It keeps the normal LinearSVC API and behavior, then implements predict_proba() from the classifier's decision_function() output.

This is useful when downstream sklearn tools expect probability-shaped output. One motivating case in the source is multiclass ROC AUC, where roc_auc_score() requires per-class scores that sum to 1.

How It Works

predict_proba(X) calls decision_function(X) and passes the resulting margins through genetools.stats.run_sigmoid_if_binary_and_softmax_if_multiclass():

  • binary classifiers use a sigmoid transform and return shape (n_samples, 2);
  • multiclass classifiers use a softmax transform and return shape (n_samples, n_classes).

Rows are normalized to sum to 1, matching the shape expected from sklearn classifiers with predict_proba().

Important Limitation

The returned values are uncalibrated. They are transformed SVM decision margins, not calibrated probability estimates. Use them when you need normalized probability-like scores for sklearn APIs, not when you need well-calibrated confidence values. For calibrated probabilities, use sklearn's calibration tools instead.

Installation

pip install uncalibrated_linearsvc

The package requires Python 3.8 or newer and depends on numpy, scikit-learn, and genetools.

Usage

from uncalibrated_linearsvc import LinearSVCWithUncalibratedProbabilities

clf = LinearSVCWithUncalibratedProbabilities(
    dual=False,
    multi_class="ovr",
    random_state=0,
)

clf.fit(X_train, y_train)

predictions = clf.predict(X_test)
probability_like_scores = clf.predict_proba(X_test)

Because the class subclasses LinearSVC, constructor arguments such as dual, multi_class, and random_state are the same as in scikit-learn.

Development

pip install -r requirements_dev.txt
pip install -e .
make test
make lint

The test suite covers binary and multiclass predict_proba() shape handling and row normalization.

Changelog

0.0.1

  • First release on PyPI.

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

uncalibrated_linearsvc-0.0.2.tar.gz (11.9 kB view details)

Uploaded Source

Built Distribution

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

uncalibrated_linearsvc-0.0.2-py2.py3-none-any.whl (4.6 kB view details)

Uploaded Python 2Python 3

File details

Details for the file uncalibrated_linearsvc-0.0.2.tar.gz.

File metadata

  • Download URL: uncalibrated_linearsvc-0.0.2.tar.gz
  • Upload date:
  • Size: 11.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for uncalibrated_linearsvc-0.0.2.tar.gz
Algorithm Hash digest
SHA256 e12473b328d549993fecf3d16e5bbf2e479567b944fc94fe5ffff6a662fc249d
MD5 5ea925319ad47428899ed41a6f786aa5
BLAKE2b-256 8b8d6cdcc3580efe7006bf4bce78a91f5f761c0b42e1845118e63242c019abf3

See more details on using hashes here.

File details

Details for the file uncalibrated_linearsvc-0.0.2-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for uncalibrated_linearsvc-0.0.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 d159253fdeb9f8e63f29eb25aeae22e1e58f967308f7574209e6cab34f0eec9f
MD5 dc2f0874046ef44e88fad71193461fa8
BLAKE2b-256 25c99cd7301ecee968ef27ddadf1a2525dc9761121483fb9a57cbada94f87a38

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