scikit-learn 1.9.0
Overview
Scikit-learn 1.9.0 (June 2026) is the Python machine learning library built on NumPy, SciPy, and joblib. All estimators follow a unified API: fit(), predict() (predictors), transform() (transformers). The library ships with ~130+ estimators across classification, regression, clustering, dimensionality reduction, preprocessing, model selection, and metrics.
Key 1.9 additions:
- Callback API (
sklearn.callback) — progress bars and scoring monitors during fitting
- FrozenEstimator (
sklearn.frozen) — wrap fitted estimators to prevent re-fitting in pipelines
- sparse_interface config — control sparse matrix vs array output
- narwhals dependency — improved pandas/Polars dataframe support
metric_at_thresholds() for computing metrics across all thresholds
- Tree models now handle missing values (NaN) natively in dense data
Dependencies: Python 3.11+, NumPy >= 1.24.1, SciPy >= 1.10.0, joblib >= 1.4.0, narwhals >= 2.0.1, threadpoolctl >= 3.5.0.
Usage
Estimator Pattern (all models)
from sklearn.ensemble import RandomForestClassifier
model = RandomForestClassifier(n_estimators=100, random_state=42)
model.fit(X_train, y_train) # Train
y_pred = model.predict(X_test) # Predict
y_proba = model.predict_proba(X_test) # Probabilities (classifiers)
score = model.score(X_test, y_test) # Default metric
Pipeline Pattern (recommended for production)
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.ensemble import RandomForestClassifier
pipe = Pipeline([
("scaler", StandardScaler()),
("clf", RandomForestClassifier(random_state=42)),
])
pipe.fit(X_train, y_train)
pipe.predict(X_test)
Model Selection Pattern
from sklearn.model_selection import cross_validate, GridSearchCV
# Quick evaluation
cv_results = cross_validate(pipe, X, y, cv=5,
scoring=["accuracy", "f1"])
# Hyperparameter tuning
search = GridSearchCV(
pipe,
param_grid={"clf__n_estimators": [50, 100, 200]},
cv=5, scoring="f1"
)
search.fit(X_train, y_train)
search.best_params_
Column-Wise Preprocessing (mixed feature types)
from sklearn.compose import ColumnTransformer
from sklearn.preprocessing import OneHotEncoder, StandardScaler
preprocessor = ColumnTransformer([
("num", StandardScaler(), numeric_cols),
("cat", OneHotEncoder(handle_unknown="infrequent_if_exist"), categorical_cols),
])
Callbacks (new in 1.9)
from sklearn.callback import ProgressBar, ScoringMonitor
# During fitting of supported estimators
model.fit(X, y, callbacks=[ProgressBar()])
Gotchas
load_boston removed since 1.2 — use fetch_california_housing or fetch_openml(name="house_prices") instead. The Boston dataset had ethical issues (racially biased variable).
SVC(probability=True) deprecated in 1.9 — not thread-safe. Use CalibratedClassifierCV(svc, ensemble=False) for probability estimates instead.
criterion="friedman_mse" deprecated in tree regressors — it was buggy and identical to "squared_error". Use "squared_error" instead.
TargetEncoder(shuffle=...) deprecated — pass a CV generator via cv argument instead.
LogisticRegressionCV(scoring) default changing — will switch from None (accuracy) to "neg_log_loss" in v1.11. Explicitly set scoring now.
n_alphas deprecated in lasso_path/enet_path — pass alphas directly as int or array-like.
sample_weight with all zeros raises ValueError — validate weights before passing.
- Pipeline parameter access uses double underscore —
pipe.set_params(clf__C=0.1) not pipe.clf.C = 0.1.
clone() resets fitted state — use sklearn.base.clone() to get a fresh unfitted copy with same hyperparameters.
- RandomForest/ExtraTrees
max_samples behavior changed — when float, interpreted as fraction of sample_weight.sum(), not X.shape[0]. Integer max_samples > n_samples now allowed.
FrozenEstimator.__sklearn_clone__ returns self — cloning a frozen estimator doesn't clone the inner estimator. This is intentional (prevents re-fitting).
- Sparse interface config defaults to
"spmatrix" — will change to "sparray" in future releases. Set explicitly if you need sparse arrays now.
References
- 01-core-api — BaseEstimator, mixins, Pipeline, ColumnTransformer, clone, config
- 02-classifiers — All classification estimators and their key parameters
- 03-regressors — All regression estimators and their key parameters
- 04-clustering — Clustering algorithms: KMeans, DBSCAN, Agglomerative, etc.
- 05-preprocessing — Scalers, encoders, imputers, transformers
- 06-model-selection — CV splitters, GridSearchCV, cross_validate, learning curves
- 07-metrics — Classification/regression metrics, scorers, display classes
- 08-feature-selection — RFE, SelectKBest, VarianceThreshold, mutual info
- 09-dimensionality-reduction — PCA, SVD, NMF, manifold methods
- 10-data-io — Built-in datasets, fetch_openml, synthetic data generators
- 11-advanced-topics — Callbacks, metadata routing, FrozenEstimator, experimental features
1---2name: scikit-learn-1-9-03description: Comprehensive guide to scikit-learn 1.9.0 — the Python machine learning library. Use when working with ML models, pipelines, preprocessing, model selection, metrics, or any data science task using scikit-learn. Covers classification, regression, clustering, dimensionality reduction, ensemble methods, hyperparameter tuning, cross-validation, feature engineering, and more. Trigger on: sklearn, scikit-learn, machine learning, ML pipeline, model training, cross-validation, GridSearchCV, Random Forest, SVM, logistic regression, PCA, KMeans, train_test_split, metrics.4---56# scikit-learn 1.9.078## Overview910Scikit-learn 1.9.0 (June 2026) is the Python machine learning library built on NumPy, SciPy, and joblib. All estimators follow a unified API: `fit()`, `predict()` (predictors), `transform()` (transformers). The library ships with ~130+ estimators across classification, regression, clustering, dimensionality reduction, preprocessing, model selection, and metrics.1112**Key 1.9 additions:**13- **Callback API** (`sklearn.callback`) — progress bars and scoring monitors during fitting14- **FrozenEstimator** (`sklearn.frozen`) — wrap fitted estimators to prevent re-fitting in pipelines15- **sparse_interface config** — control sparse matrix vs array output16- **narwhals dependency** — improved pandas/Polars dataframe support17- `metric_at_thresholds()` for computing metrics across all thresholds18- Tree models now handle missing values (NaN) natively in dense data1920**Dependencies:** Python 3.11+, NumPy >= 1.24.1, SciPy >= 1.10.0, joblib >= 1.4.0, narwhals >= 2.0.1, threadpoolctl >= 3.5.0.2122## Usage2324### Estimator Pattern (all models)2526```python27from sklearn.ensemble import RandomForestClassifier2829model = RandomForestClassifier(n_estimators=100, random_state=42)30model.fit(X_train, y_train) # Train31y_pred = model.predict(X_test) # Predict32y_proba = model.predict_proba(X_test) # Probabilities (classifiers)33score = model.score(X_test, y_test) # Default metric34```3536### Pipeline Pattern (recommended for production)3738```python39from sklearn.pipeline import Pipeline40from sklearn.preprocessing import StandardScaler41from sklearn.ensemble import RandomForestClassifier4243pipe = Pipeline([44 ("scaler", StandardScaler()),45 ("clf", RandomForestClassifier(random_state=42)),46])47pipe.fit(X_train, y_train)48pipe.predict(X_test)49```5051### Model Selection Pattern5253```python54from sklearn.model_selection import cross_validate, GridSearchCV5556# Quick evaluation57cv_results = cross_validate(pipe, X, y, cv=5,58 scoring=["accuracy", "f1"])5960# Hyperparameter tuning61search = GridSearchCV(62 pipe,63 param_grid={"clf__n_estimators": [50, 100, 200]},64 cv=5, scoring="f1"65)66search.fit(X_train, y_train)67search.best_params_68```6970### Column-Wise Preprocessing (mixed feature types)7172```python73from sklearn.compose import ColumnTransformer74from sklearn.preprocessing import OneHotEncoder, StandardScaler7576preprocessor = ColumnTransformer([77 ("num", StandardScaler(), numeric_cols),78 ("cat", OneHotEncoder(handle_unknown="infrequent_if_exist"), categorical_cols),79])80```8182### Callbacks (new in 1.9)8384```python85from sklearn.callback import ProgressBar, ScoringMonitor8687# During fitting of supported estimators88model.fit(X, y, callbacks=[ProgressBar()])89```9091## Gotchas9293- **`load_boston` removed since 1.2** — use `fetch_california_housing` or `fetch_openml(name="house_prices")` instead. The Boston dataset had ethical issues (racially biased variable).94- **`SVC(probability=True)` deprecated in 1.9** — not thread-safe. Use `CalibratedClassifierCV(svc, ensemble=False)` for probability estimates instead.95- **`criterion="friedman_mse"` deprecated** in tree regressors — it was buggy and identical to `"squared_error"`. Use `"squared_error"` instead.96- **`TargetEncoder(shuffle=...)` deprecated** — pass a CV generator via `cv` argument instead.97- **`LogisticRegressionCV(scoring)` default changing** — will switch from `None` (accuracy) to `"neg_log_loss"` in v1.11. Explicitly set `scoring` now.98- **`n_alphas` deprecated** in `lasso_path`/`enet_path` — pass `alphas` directly as int or array-like.99- **`sample_weight` with all zeros raises ValueError** — validate weights before passing.100- **Pipeline parameter access uses double underscore** — `pipe.set_params(clf__C=0.1)` not `pipe.clf.C = 0.1`.101- **`clone()` resets fitted state** — use `sklearn.base.clone()` to get a fresh unfitted copy with same hyperparameters.102- **RandomForest/ExtraTrees `max_samples` behavior changed** — when float, interpreted as fraction of `sample_weight.sum()`, not `X.shape[0]`. Integer `max_samples > n_samples` now allowed.103- **`FrozenEstimator.__sklearn_clone__` returns self** — cloning a frozen estimator doesn't clone the inner estimator. This is intentional (prevents re-fitting).104- **Sparse interface config defaults to `"spmatrix"`** — will change to `"sparray"` in future releases. Set explicitly if you need sparse arrays now.105106## References107108- [01-core-api](references/01-core-api.md) — BaseEstimator, mixins, Pipeline, ColumnTransformer, clone, config109- [02-classifiers](references/02-classifiers.md) — All classification estimators and their key parameters110- [03-regressors](references/03-regressors.md) — All regression estimators and their key parameters111- [04-clustering](references/04-clustering.md) — Clustering algorithms: KMeans, DBSCAN, Agglomerative, etc.112- [05-preprocessing](references/05-preprocessing.md) — Scalers, encoders, imputers, transformers113- [06-model-selection](references/06-model-selection.md) — CV splitters, GridSearchCV, cross_validate, learning curves114- [07-metrics](references/07-metrics.md) — Classification/regression metrics, scorers, display classes115- [08-feature-selection](references/08-feature-selection.md) — RFE, SelectKBest, VarianceThreshold, mutual info116- [09-dimensionality-reduction](references/09-dimensionality-reduction.md) — PCA, SVD, NMF, manifold methods117- [10-data-io](references/10-data-io.md) — Built-in datasets, fetch_openml, synthetic data generators118- [11-advanced-topics](references/11-advanced-topics.md) — Callbacks, metadata routing, FrozenEstimator, experimental features