5
5
6
6
from abc import ABCMeta , abstractmethod
7
7
from contextlib import suppress
8
- from typing import Any , List
9
8
10
9
import numpy as np
11
10
18
17
19
18
20
19
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.
23
21
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
+ """
25
30
26
31
@abstractmethod
27
32
def __init__ (self ):
@@ -51,10 +56,10 @@ def _get_params(self, attr, deep=True):
51
56
52
57
def _set_params (self , attr , ** params ):
53
58
# Ensure strict ordering of parameter setting:
54
- # 1. All steps
59
+ # 1. Replace the entire estimators collection
55
60
if attr in params :
56
61
setattr (self , attr , params .pop (attr ))
57
- # 2. Replace items with estimators in params
62
+ # 2. Replace individual estimators by name
58
63
items = getattr (self , attr )
59
64
if isinstance (items , list ) and items :
60
65
# Get item names used to identify valid names in params
@@ -66,7 +71,7 @@ def _set_params(self, attr, **params):
66
71
if "__" not in name and name in item_names :
67
72
self ._replace_estimator (attr , name , params .pop (name ))
68
73
69
- # 3. Step parameters and other initialisation arguments
74
+ # 3. Individual estimator parameters and other initialisation arguments
70
75
super ().set_params (** params )
71
76
return self
72
77
0 commit comments