Skip to content

Commit a1512d5

Browse files
[ADD] documentation for pipelines and steps (#329)
* Add documentation for pipelines and steps * fix flake * Apply suggestions from code review Co-authored-by: nabenabe0928 <[email protected]> * accept shuhei's suggestions Co-authored-by: nabenabe0928 <[email protected]>
1 parent f6af46f commit a1512d5

10 files changed

+384
-144
lines changed

autoPyTorch/api/tabular_classification.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ def search(
148148
Fit both optimizes the machine learning models and builds an ensemble out of them.
149149
To disable ensembling, set ensemble_size==0.
150150
using the optimizer.
151+
151152
Args:
152153
X_train, y_train, X_test, y_test: Union[np.ndarray, List, pd.DataFrame]
153154
A pair of features (X_train) and targets (y_train) used to fit a

autoPyTorch/api/tabular_regression.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ def search(
149149
Fit both optimizes the machine learning models and builds an ensemble out of them.
150150
To disable ensembling, set ensemble_size==0.
151151
using the optimizer.
152+
152153
Args:
153154
X_train, y_train, X_test, y_test: Union[np.ndarray, List, pd.DataFrame]
154155
A pair of features (X_train) and targets (y_train) used to fit a

autoPyTorch/pipeline/base_pipeline.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,16 @@
2929

3030

3131
class BasePipeline(Pipeline):
32-
"""Base class for all pipeline objects.
32+
"""
33+
Base class for all pipeline objects.
3334
3435
Args:
3536
config (Optional[Configuration]):
3637
Allows to directly specify a configuration space
3738
steps (Optional[List[Tuple[str, PipelineStepType]]]):
38-
the list of steps that build the pipeline. If provided,
39-
they won't be dynamically produced.
39+
The list of `autoPyTorchComponent` or `autoPyTorchChoice`
40+
that build the pipeline. If provided, they won't be
41+
dynamically produced.
4042
include (Optional[Dict[str, Any]]):
4143
Allows the caller to specify which configurations to honor during
4244
the creation of the configuration space.
@@ -46,12 +48,12 @@ class BasePipeline(Pipeline):
4648
random_state (np.random.RandomState):
4749
allows to produce reproducible results by
4850
setting a seed for randomized settings
49-
init_params (Optional[Dict[str, Any]])
51+
init_params (Optional[Dict[str, Any]]):
52+
Optional initial settings for the config
5053
search_space_updates (Optional[HyperparameterSearchSpaceUpdates]):
5154
search space updates that can be used to modify the search
5255
space of particular components or choice modules of the pipeline
5356
54-
5557
Attributes:
5658
steps (List[Tuple[str, PipelineStepType]]):
5759
the steps of the current pipeline. Each step in an AutoPyTorch

autoPyTorch/pipeline/components/base_choice.py

Lines changed: 49 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,22 @@
1616

1717

1818
class autoPyTorchChoice(object):
19-
"""Allows for the dynamically generation of components as pipeline steps.
19+
"""
20+
Allows for the dynamically generation of components as pipeline steps.
2021
2122
Args:
22-
dataset_properties (Dict[str, Union[str, BaseDatasetPropertiesType]]): Describes the dataset
23-
to work on
24-
random_state (Optional[np.random.RandomState]): allows to produce reproducible
25-
results by setting a seed for randomized settings
23+
dataset_properties (Dict[str, Union[str, BaseDatasetPropertiesType]]):
24+
Describes the dataset to work on
25+
random_state (Optional[np.random.RandomState]):
26+
Allows to produce reproducible results by setting a
27+
seed for randomized settings
2628
2729
Attributes:
28-
random_state (Optional[np.random.RandomState]): allows to produce reproducible
29-
results by setting a seed for randomized settings
30-
choice (autoPyTorchComponent): the choice of components for this stage
30+
random_state (Optional[np.random.RandomState]):
31+
Allows to produce reproducible results by setting a seed for
32+
randomized settings
33+
choice (autoPyTorchComponent):
34+
the choice of components for this stage
3135
"""
3236
def __init__(self,
3337
dataset_properties: Dict[str, BaseDatasetPropertiesType],
@@ -67,11 +71,13 @@ def get_components(cls: 'autoPyTorchChoice') -> Dict[str, autoPyTorchComponent]:
6771
for current step.
6872
6973
Args:
70-
cls (autoPyTorchChoice): The choice object from which to query the valid
74+
cls (autoPyTorchChoice):
75+
The choice object from which to query the valid
7176
components
7277
7378
Returns:
74-
Dict[str, autoPyTorchComponent]: The available components via a mapping
79+
Dict[str, autoPyTorchComponent]:
80+
The available components via a mapping
7581
from the module name to the component class
7682
7783
"""
@@ -88,10 +94,13 @@ def get_available_components(
8894
user specification
8995
9096
Args:
91-
dataset_properties (Optional[Dict[str, BaseDatasetPropertiesType]]): Describes the dataset to work on
92-
include: Optional[Dict[str, Any]]: what components to include. It is an exhaustive
97+
dataset_properties (Optional[Dict[str, BaseDatasetPropertiesType]]):
98+
Describes the dataset to work on
99+
include: Optional[Dict[str, Any]]:
100+
what components to include. It is an exhaustive
93101
list, and will exclusively use this components.
94-
exclude: Optional[Dict[str, Any]]: which components to skip
102+
exclude: Optional[Dict[str, Any]]:
103+
which components to skip. Can't be used together with include
95104
96105
Results:
97106
Dict[str, autoPyTorchComponent]: A dictionary with valid components for this
@@ -137,10 +146,10 @@ def set_hyperparameters(self,
137146
to an actual parameter of the autoPyTorch component.
138147
139148
Args:
140-
configuration (Configuration): which configuration to apply to
141-
the chosen component
142-
init_params (Optional[Dict[str, any]]): Optional arguments to
143-
initialize the chosen component
149+
configuration (Configuration):
150+
Which configuration to apply to the chosen component
151+
init_params (Optional[Dict[str, any]]):
152+
Optional arguments to initialize the chosen component
144153
145154
Returns:
146155
self: returns an instance of self
@@ -177,11 +186,15 @@ def get_hyperparameter_search_space(
177186
"""Returns the configuration space of the current chosen components
178187
179188
Args:
180-
dataset_properties (Optional[Dict[str, BaseDatasetPropertiesType]]): Describes the dataset to work on
181-
default: (Optional[str]) : Default component to use in hyperparameters
182-
include: Optional[Dict[str, Any]]: what components to include. It is an exhaustive
189+
dataset_properties (Optional[Dict[str, BaseDatasetPropertiesType]]):
190+
Describes the dataset to work on
191+
default: (Optional[str]):
192+
Default component to use in hyperparameters
193+
include: Optional[Dict[str, Any]]:
194+
what components to include. It is an exhaustive
183195
list, and will exclusively use this components.
184-
exclude: Optional[Dict[str, Any]]: which components to skip
196+
exclude: Optional[Dict[str, Any]]:
197+
which components to skip
185198
186199
Returns:
187200
ConfigurationSpace: the configuration space of the hyper-parameters of the
@@ -193,8 +206,10 @@ def fit(self, X: Dict[str, Any], y: Any) -> autoPyTorchComponent:
193206
"""Handy method to check if a component is fitted
194207
195208
Args:
196-
X (X: Dict[str, Any]): Dependencies needed by current component to perform fit
197-
y (Any): not used. To comply with sklearn API
209+
X (X: Dict[str, Any]):
210+
Dependencies needed by current component to perform fit
211+
y (Any):
212+
not used. To comply with sklearn API
198213
"""
199214
# Allows to use check_is_fitted on the choice object
200215
self.fitted_ = True
@@ -205,19 +220,23 @@ def predict(self, X: np.ndarray) -> np.ndarray:
205220
"""Predicts the target given an input, by using the chosen component
206221
207222
Args:
208-
X (np.ndarray): input features from which to predict the target
223+
X (np.ndarray):
224+
input features from which to predict the target
209225
210226
Returns:
211-
np.ndarray: the predicted target
227+
np.ndarray:
228+
the target prediction
212229
"""
213230
assert self.choice is not None, "Cannot call predict without initializing the component"
214231
return self.choice.predict(X)
215232

216233
def transform(self, X: Dict[str, Any]) -> Dict[str, Any]:
217234
"""
218235
Adds the current choice in the fit dictionary
236+
219237
Args:
220-
X (Dict[str, Any]): fit dictionary
238+
X (Dict[str, Any]):
239+
fit dictionary
221240
222241
Returns:
223242
(Dict[str, Any])
@@ -233,7 +252,8 @@ def check_requirements(self, X: Dict[str, Any], y: Any = None) -> None:
233252
are honored before fit.
234253
235254
Args:
236-
X (Dict[str, Any]): Dictionary with fitted parameters. It is a message passing
255+
X (Dict[str, Any]):
256+
Dictionary with fitted parameters. It is a message passing
237257
mechanism, in which during a transform, a components adds relevant information
238258
so that further stages can be properly fitted
239259
"""
@@ -246,7 +266,8 @@ def _check_dataset_properties(self, dataset_properties: Dict[str, BaseDatasetPro
246266
"""
247267
A mechanism in code to ensure the correctness of the initialised dataset properties.
248268
Args:
249-
dataset_properties:
269+
dataset_properties (Dict[str, BaseDatasetPropertiesType]):
270+
Describes the dataset to work on
250271
251272
"""
252273
assert isinstance(dataset_properties, dict), "dataset_properties must be a dictionary"

autoPyTorch/pipeline/components/base_component.py

Lines changed: 46 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,12 @@ def find_components(
2727
that inherit from base_class
2828
2929
Args:
30-
package (str): The associated package that contains the components
31-
directory (str): The directory from which to extract the components
32-
base_class (BaseEstimator): base class to filter out desired components
30+
package (str):
31+
The associated package that contains the components
32+
directory (str):
33+
The directory from which to extract the components
34+
base_class (BaseEstimator):
35+
base class to filter out desired components
3336
that don't inherit from this class
3437
"""
3538
components = OrderedDict()
@@ -60,7 +63,8 @@ class ThirdPartyComponents(object):
6063
space to work.
6164
6265
Args:
63-
base_class (BaseEstimator) component type desired to be created
66+
base_class (BaseEstimator):
67+
Component type desired to be created
6468
"""
6569

6670
def __init__(self, base_class: BaseEstimator):
@@ -96,6 +100,16 @@ def add_component(self, obj: BaseEstimator) -> None:
96100

97101

98102
class autoPyTorchComponent(BaseEstimator):
103+
"""
104+
Provides an abstract interface which can be used to
105+
create steps of a pipeline in AutoPyTorch.
106+
107+
Args:
108+
random_state (Optional[np.random.RandomState]):
109+
Allows to produce reproducible results by setting a
110+
seed for randomized settings
111+
112+
"""
99113
_required_properties: Optional[List[str]] = None
100114

101115
def __init__(self, random_state: Optional[np.random.RandomState] = None) -> None:
@@ -115,7 +129,8 @@ def get_required_properties(cls) -> Optional[List[str]]:
115129
Usually defined in the base class of the component
116130
117131
Returns:
118-
List[str]: list of properties autopytorch component must have for proper functioning of the pipeline
132+
List[str]:
133+
list of properties autopytorch component must have for proper functioning of the pipeline
119134
"""
120135
return cls._required_properties
121136

@@ -125,8 +140,8 @@ def get_fit_requirements(self) -> Optional[List[FitRequirement]]:
125140
that need to be in the fit dictionary
126141
127142
Returns:
128-
List[FitRequirement]: a list containing required keys
129-
in a named tuple (name: str, type: object)
143+
List[FitRequirement]:
144+
a list containing required keys in a named tuple (name: str, type: object)
130145
"""
131146
return self._fit_requirements
132147

@@ -139,11 +154,12 @@ def get_properties(dataset_properties: Optional[Dict[str, BaseDatasetPropertiesT
139154
"""Get the properties of the underlying algorithm.
140155
141156
Args:
142-
dataset_properties (Optional[Dict[str, Union[str, int]]): Describes the dataset
143-
to work on
157+
dataset_properties (Optional[Dict[str, Union[str, int]]):
158+
Describes the dataset to work on
144159
145160
Returns:
146-
Dict[str, Any]: Properties of the algorithm
161+
Dict[str, Any]:
162+
Properties of the algorithm
147163
"""
148164
raise NotImplementedError()
149165

@@ -154,11 +170,12 @@ def get_hyperparameter_search_space(
154170
"""Return the configuration space of this classification algorithm.
155171
156172
Args:
157-
dataset_properties (Optional[Dict[str, Union[str, int]]): Describes the dataset
158-
to work on
173+
dataset_properties (Optional[Dict[str, Union[str, int]]):
174+
Describes the dataset to work on
159175
160176
Returns:
161-
ConfigurationSpace: The configuration space of this algorithm.
177+
ConfigurationSpace:
178+
The configuration space of this algorithm.
162179
"""
163180
raise NotImplementedError()
164181

@@ -167,13 +184,16 @@ def fit(self, X: Dict[str, Any], y: Any = None) -> "autoPyTorchComponent":
167184
model and returns `self`.
168185
169186
Args:
170-
X (Dict[str, Any]): Dictionary with fitted parameters. It is a message passing
187+
X (Dict[str, Any]):
188+
Dictionary with fitted parameters. It is a message passing
171189
mechanism, in which during a transform, a components adds relevant information
172190
so that further stages can be properly fitted
173-
y (Any): Not Used -- to comply with API
191+
y (Any):
192+
Not Used -- to comply with API
174193
175194
Returns:
176-
self : returns an instance of self.
195+
self:
196+
returns an instance of self.
177197
178198
Notes:
179199
Please see the `scikit-learn API documentation
@@ -192,10 +212,10 @@ def set_hyperparameters(self,
192212
to an actual parameter of the autoPyTorch component.
193213
194214
Args:
195-
configuration (Configuration): which configuration to apply to
196-
the chosen component
197-
init_params (Optional[Dict[str, any]]): Optional arguments to
198-
initialize the chosen component
215+
configuration (Configuration):
216+
Which configuration to apply to the chosen component
217+
init_params (Optional[Dict[str, any]]):
218+
Optional arguments to initialize the chosen component
199219
200220
Returns:
201221
An instance of self
@@ -226,7 +246,8 @@ def check_requirements(self, X: Dict[str, Any], y: Any = None) -> None:
226246
are honored before fit.
227247
228248
Args:
229-
X (Dict[str, Any]): Dictionary with fitted parameters. It is a message passing
249+
X (Dict[str, Any]):
250+
Dictionary with fitted parameters. It is a message passing
230251
mechanism, in which during a transform, a components adds relevant information
231252
so that further stages can be properly fitted
232253
"""
@@ -267,10 +288,12 @@ def _apply_search_space_update(self, hyperparameter_search_space_update: Hyperpa
267288
"""Allows the user to update a hyperparameter
268289
269290
Args:
270-
name (str): name of hyperparameter
291+
name (str):
292+
name of hyperparameter
271293
new_value_range (List[Union[int, str, float]]):
272294
value range can be either lower, upper or a list of possible candidates
273-
log (bool): Whether to use log scale
295+
log (bool):
296+
Whether to use log scale
274297
"""
275298

276299
self._cs_updates[hyperparameter_search_space_update.hyperparameter] = hyperparameter_search_space_update

0 commit comments

Comments
 (0)