Implementation:Scikit learn Scikit learn LinkFunctions
| Knowledge Sources | |
|---|---|
| Domains | Machine Learning, Statistical Modeling |
| Last Updated | 2026-02-08 15:00 GMT |
Overview
Concrete tool for defining invertible and differentiable link functions used in generalized linear models, provided by scikit-learn.
Description
This module contains classes for invertible (and differentiable) link functions. It defines an abstract base class BaseLink along with concrete implementations such as IdentityLink, LogLink, LogitLink, and MultinomialLogit. It also includes the Interval dataclass for validating value ranges and a helper function _inclusive_low_high for testing purposes.
Usage
Use link functions when working with generalized linear models (GLMs) to transform between the linear predictor space and the predicted mean space. These are primarily used internally by scikit-learn's loss functions and GLM estimators.
Code Reference
Source Location
- Repository: scikit-learn
- File: sklearn/_loss/link.py
Signature
@dataclass
class Interval:
low: float
high: float
low_inclusive: bool
high_inclusive: bool
class BaseLink(ABC):
is_multiclass = False
interval_y_pred = Interval(-np.inf, np.inf, False, False)
Import
from sklearn._loss.link import BaseLink, Interval
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| raw_prediction | ndarray | Yes | Raw prediction values (linear predictor) to be transformed via inverse link |
| y_pred | ndarray | Yes | Predicted values to be transformed via the link function |
Outputs
| Name | Type | Description |
|---|---|---|
| raw_prediction | ndarray | Result of applying the link function g(y_pred) |
| y_pred | ndarray | Result of applying the inverse link h(raw_prediction) |
Usage Examples
Basic Usage
import numpy as np
from sklearn._loss.link import LogitLink
link = LogitLink()
y_pred = np.array([0.2, 0.5, 0.8])
raw = link.link(y_pred)
y_back = link.inverse(raw)
print(y_back) # array([0.2, 0.5, 0.8])