Skip to content

Commit e3b383a

Browse files
authored
MNT remove the steps attribute from _BaseComposition (#32040)
1 parent 42b6fc8 commit e3b383a

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

sklearn/utils/metaestimators.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
from abc import ABCMeta, abstractmethod
77
from contextlib import suppress
8-
from typing import Any, List
98

109
import numpy as np
1110

@@ -18,10 +17,16 @@
1817

1918

2019
class _BaseComposition(BaseEstimator, metaclass=ABCMeta):
21-
"""Handles parameter management for estimators that are composed of named
22-
sub-estimators."""
20+
"""Base class for estimators that are composed of named sub-estimators.
2321
24-
steps: List[Any]
22+
This abstract class provides parameter management functionality for
23+
meta-estimators that contain collections of named estimators. It handles
24+
the complex logic for getting and setting parameters on nested estimators
25+
using the "estimator_name__parameter" syntax.
26+
27+
The class is designed to work with any attribute containing a list of
28+
(name, estimator) tuples.
29+
"""
2530

2631
@abstractmethod
2732
def __init__(self):
@@ -51,10 +56,10 @@ def _get_params(self, attr, deep=True):
5156

5257
def _set_params(self, attr, **params):
5358
# Ensure strict ordering of parameter setting:
54-
# 1. All steps
59+
# 1. Replace the entire estimators collection
5560
if attr in params:
5661
setattr(self, attr, params.pop(attr))
57-
# 2. Replace items with estimators in params
62+
# 2. Replace individual estimators by name
5863
items = getattr(self, attr)
5964
if isinstance(items, list) and items:
6065
# Get item names used to identify valid names in params
@@ -66,7 +71,7 @@ def _set_params(self, attr, **params):
6671
if "__" not in name and name in item_names:
6772
self._replace_estimator(attr, name, params.pop(name))
6873

69-
# 3. Step parameters and other initialisation arguments
74+
# 3. Individual estimator parameters and other initialisation arguments
7075
super().set_params(**params)
7176
return self
7277

0 commit comments

Comments
 (0)