Registry / ai-ml / betacal

betacal

JSON →
library1.1.0pypypi✓ verified 22d ago

BetaCal provides a Python implementation of Beta Calibration, a method for calibrating predicted probabilities from binary classifiers. It offers a well-founded and easily implemented improvement over traditional logistic calibration, particularly effective when classifiers suffer from scores that tend too much to the extremes or when an already well-calibrated model might be uncalibrated by logistic methods. The current version is 1.1.0, last released in April 2021. While functional and widely cited, the package's release cadence is slow, suggesting a maintenance rather than active development phase.

pip install betacal
INSTALL
IMPORT
SIG · BETACAL
B
betacal
ai-mlpythonv1.1.0
Install
9.8s avg
Import
3698ms
Disk
280MB
Pass rate
5/ 10
Env Coverage5 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.1.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
build_error
glibc
py 3.103.95 runs
installs and imports cleanly · install 9.8s · import 3.698s · 270MB
280MB installed
● package 280MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

BetaCalibration
from betacal import BetaCalibration

Demonstrates how to initialize, fit, and use BetaCalibration to transform raw classifier scores into calibrated probabilities. It uses synthetic data to illustrate the basic workflow.

import numpy as np from betacal import BetaCalibration # Generate some dummy data np.random.seed(42) scores = np.random.rand(100) # Raw classifier scores (probabilities) labels = np.random.randint(0, 2, 100) # True binary labels # Initialize BetaCalibration with default 'abm' parameters # 'abm' (alpha, beta, mu) is a three-parameter model bc = BetaCalibration(parameters='abm') # Fit the calibrator to the scores and true labels bc.fit(scores, labels) # Predict calibrated probabilities calibrated_scores = bc.predict(scores) print(f"Original scores (first 5): {scores[:5].round(3)}") print(f"Calibrated scores (first 5): {calibrated_scores[:5].round(3)}")
Debug
Known issues
gotchaThe `betacal` library has not seen a new release since April 2021. While the existing version is stable and functional, users should be aware that active development and new features are not frequently added.
fix
Review the GitHub repository (https://github.com/betacal/python) for any unreleased updates or forks if requiring more recent maintenance or features.
affects: 1.1.0 and earlier
gotchaChoosing the correct `parameters` for `BetaCalibration` ('abm', 'ab', 'am') is crucial. 'abm' is a three-parameter model, 'ab' is a two-parameter model, and 'am' is a one-parameter model. An incorrect choice without understanding the underlying Beta distribution models can lead to suboptimal calibration, especially if the data distribution doesn't align with the chosen model complexity.
fix
Consult the `betacal` documentation and tutorials to understand the implications of each parameter choice. Experiment with different `parameters` settings and evaluate calibration performance (e.g., using reliability diagrams) on validation data.
affects: All
gotchaBeta Calibration is designed to address specific shortcomings of Logistic Calibration, such as uncalibrating already well-calibrated models or performing poorly when scores are at the extremes. It's an alternative to logistic and isotonic calibration, not a direct drop-in replacement without considering these specific benefits.
fix
Understand the theoretical background and use cases for Beta Calibration. If transitioning from other calibration methods, evaluate `betacal`'s performance thoroughly on your specific dataset to confirm its benefits for your use case.
affects: All
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'betacal'
The `betacal` package is not installed in the current Python environment, or the environment where it's installed is not active.
fix
Install the package using pip: `pip install betacal`
ValueError: 'invalid_param' is not a valid parameter choice. Choose from 'abm', 'ab', 'am'.
The `parameters` argument provided to the `BetaCalibration` constructor is not one of the allowed string values ('abm', 'ab', 'am').
fix
Use one of the valid parameter choices for `BetaCalibration`: `cal = BetaCalibration(parameters='abm')` (or 'ab', 'am').
ValueError: Expected 2D array, got 1D array instead: array=[...]. Reshape your data using X.reshape(-1, 1) if it contains a single feature or X.reshape(1, -1) if it contains a single sample.
The input probability scores (X) provided to the `fit` or `predict` method of `BetaCalibration` are a 1D array, but the scikit-learn-like API expects a 2D array (e.g., `(n_samples, 1)` for a single feature).
fix
Reshape your 1D input array `X` to a 2D array before passing it to `fit` or `predict`: `X_reshaped = X.reshape(-1, 1)`
Upgrade
Version history
1.1.0latest on PyPI · released Apr 1, 2021
Audit
Dependencies
numpyrequiredFundamental package for numerical computation.
scikit-learnrequiredMachine learning utilities and compatibility.
Agent activity
26 hits · last 30 days
node
24
OpenAI (training)
1
Resources
betacal — pip install betacal · libregistry