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 ResponseUtils

From Leeroopedia


Knowledge Sources
Domains Machine Learning, Model Evaluation
Last Updated 2026-02-08 15:00 GMT

Overview

Concrete utility module for extracting classifier and regressor response values provided by scikit-learn.

Description

The _response module provides functions to uniformly extract response values from classifiers and regressors. It handles predict_proba, decision_function, and predict outputs for binary, multiclass, and multilabel classification scenarios, ensuring consistent shapes and proper handling of positive label selection.

Usage

Use these utilities when building scoring functions, display objects, or any code that needs to extract prediction values from estimators in a standardized way regardless of the response method used.

Code Reference

Source Location

Signature

def _process_predict_proba(*, y_pred, target_type, classes, pos_label):
    ...

def _process_decision_function(*, y_pred, target_type, classes, pos_label):
    ...

def _get_response_values_binary(
    estimator, X, *, response_method="auto", pos_label=None
):
    ...

def _get_response_values(
    estimator, X, *, response_method, pos_label=None
):
    ...

Import

from sklearn.utils._response import _get_response_values_binary, _get_response_values

I/O Contract

Inputs

Name Type Required Description
estimator estimator instance Yes A fitted classifier or regressor
X array-like Yes Input data to get predictions for
response_method str or list of str Yes The response method(s) to try (e.g., "predict_proba", "decision_function")
pos_label int, float, bool, or str No The positive class label for binary classification

Outputs

Name Type Description
y_pred ndarray Response values in a consistent format
pos_label object The resolved positive label (for binary classification)

Usage Examples

Basic Usage

from sklearn.linear_model import LogisticRegression
from sklearn.datasets import make_classification
from sklearn.utils._response import _get_response_values_binary

X, y = make_classification(random_state=42)
clf = LogisticRegression().fit(X, y)
y_pred, pos_label = _get_response_values_binary(clf, X, response_method="predict_proba")
print(y_pred.shape)  # (100,) - probabilities for positive class

Related Pages

Page Connections

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