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:Online ml River Utils ParamGrid

From Leeroopedia
Revision as of 16:12, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Online_ml_River_Utils_ParamGrid.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


Knowledge Sources
Domains Online_Learning, Hyperparameter_Tuning, Model_Selection
Last Updated 2026-02-08 16:00 GMT

Overview

Expands parameter grids for hyperparameter tuning and model selection.

Description

Generates all combinations of model parameters from a grid specification. Supports nested parameters for pipelines, tuple specifications for class instantiation, and flexible syntax. Returns list of model clones with different parameter combinations. Essential for grid search and ensemble methods.

Usage

Use with model selection techniques like SuccessiveHalvingClassifier or to generate model variants for ensemble methods. Particularly useful for comparing multiple hyperparameter configurations.

Code Reference

Source Location

Signature

def expand_param_grid(model: base.Estimator, grid: dict) -> list[base.Estimator]:
    ...

Import

from river import utils

Usage Examples

from river import linear_model, optim, utils

# Simple grid
model = linear_model.LinearRegression()
grid = {'optimizer': [optim.SGD(.1), optim.SGD(.01), optim.SGD(.001)]}
models = utils.expand_param_grid(model, grid)
print(f"Generated {len(models)} models")  # 3

# Nested class initialization
grid2 = {
    'optimizer': [
        (optim.SGD, {'lr': [.1, .01, .001]}),
        (optim.Adam, {'lr': [.1, .01, .001]})
    ]
}
models2 = utils.expand_param_grid(model, grid2)
print(f"Generated {len(models2)} models")  # 6

# Pipeline parameters
from river import feature_extraction

pipeline = (
    feature_extraction.BagOfWords() |
    linear_model.LinearRegression()
)

grid3 = {
    'BagOfWords': {
        'strip_accents': [False, True]
    },
    'LinearRegression': {
        'optimizer': [
            (optim.SGD, {'lr': [.1, .01]}),
            (optim.Adam, {'lr': [.1, .01]})
        ]
    }
}

pipeline_models = utils.expand_param_grid(pipeline, grid3)
print(f"Generated {len(pipeline_models)} pipelines")  # 8

Related Pages

Page Connections

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