Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Scikit learn Scikit learn CalibratedClassifierCV

From Leeroopedia


Knowledge Sources
Domains Calibration, Classification
Last Updated 2026-02-08 15:00 GMT

Overview

Concrete tool for calibrating predicted probabilities of classifiers using cross-validation provided by scikit-learn.

Description

CalibratedClassifierCV calibrates the predicted probabilities of a classifier using isotonic regression, sigmoid (Platt scaling), or temperature scaling. It uses cross-validation to both estimate the parameters of a classifier and subsequently calibrate it. With ensemble=True, it fits a copy of the base estimator on each training fold and calibrates it on the corresponding test fold, then averages predictions across calibrated classifiers. When ensemble=False, it uses cross-validated predictions to fit a single calibrator. If no base estimator is provided, LinearSVC is used by default.

Usage

Use CalibratedClassifierCV when you need well-calibrated probability estimates from a classifier, such as when the output probabilities need to reflect true class frequencies. It is particularly useful for classifiers like SVM that do not naturally produce calibrated probabilities, or when decision-making depends on accurate probability thresholds.

Code Reference

Source Location

Signature

class CalibratedClassifierCV(ClassifierMixin, MetaEstimatorMixin, BaseEstimator):
    def __init__(
        self,
        estimator=None,
        *,
        method="sigmoid",
        cv=None,
        n_jobs=None,
        ensemble="auto",
    ):

Import

from sklearn.calibration import CalibratedClassifierCV

I/O Contract

Inputs

Name Type Required Description
estimator estimator instance or None No Base classifier to calibrate. If None, LinearSVC(random_state=0) is used. Default is None.
method str No Calibration method: "sigmoid" (Platt scaling), "isotonic", or "temperature_scaling". Default is "sigmoid".
cv int, cross-validation generator, or "prefit" No Cross-validation strategy. Use "prefit" if the estimator is already fitted. Default is None (5-fold).
n_jobs int or None No Number of parallel jobs for cross-validation. Default is None.
ensemble bool or "auto" No Whether to return an ensemble of calibrated classifiers or a single calibrator. Default is "auto".

Outputs

Name Type Description
classes_ ndarray of shape (n_classes,) Class labels.
calibrated_classifiers_ list of _CalibratedClassifier List of calibrated classifier instances (one per CV fold when ensemble=True).
n_features_in_ int Number of features seen during fit.

Usage Examples

Basic Usage

from sklearn.calibration import CalibratedClassifierCV
from sklearn.svm import LinearSVC
from sklearn.datasets import make_classification

X, y = make_classification(n_samples=100, n_features=5, random_state=0)

svc = LinearSVC(random_state=0)
calibrated_svc = CalibratedClassifierCV(estimator=svc, cv=5)
calibrated_svc.fit(X, y)
prob = calibrated_svc.predict_proba(X)
print(prob[:5])

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment