Overview

Scikit-learn 1.5, released on June 26, 2024, adds Array API support to run estimators on different backends (NumPy, CuPy, PyTorch) and stabilizes TargetEncoder.

Main Features

Array API support

Compatible estimators now accept arrays conforming to the Array API standard, enabling transparent GPU execution via CuPy or PyTorch tensors.

python
import sklearn
sklearn.set_config(array_api_dispatch=True)

from sklearn.preprocessing import StandardScaler
import numpy as np

X = np.array([[1, 2], [3, 4], [5, 6]], dtype=np.float64)
scaler = StandardScaler()
X_scaled = scaler.fit_transform(X)
print(X_scaled)

Stabilized TargetEncoder

TargetEncoder encodes categorical features based on the target variable, with regularization to prevent overfitting.

python
from sklearn.preprocessing import TargetEncoder
import numpy as np

X = np.array([['cat'], ['dog'], ['cat'], ['bird']])
y = np.array([0.9, 0.1, 0.8, 0.5])

enc = TargetEncoder(smooth='auto')
X_enc = enc.fit_transform(X, y)
print(X_enc)

Sources