Skip to content

Instantly share code, notes, and snippets.

@elisim
Created September 2, 2021 09:26
Show Gist options
  • Save elisim/c4a6158afaf68c7247b16bdac2bad787 to your computer and use it in GitHub Desktop.
Save elisim/c4a6158afaf68c7247b16bdac2bad787 to your computer and use it in GitHub Desktop.
Hydra-Sklearn Blog - Code example 4
import hydra
from omegaconf import DictConfig
from sklearn.pipeline import Pipeline
def make_pipeline(steps_config: DictConfig) -> Pipeline:
"""Creates a pipeline with all the preprocessing steps specified in `steps_config`, ordered in a sequential manner
Args:
steps_config (DictConfig): the config containing the instructions for
creating the feature selectors or transformers
Returns:
[sklearn.pipeline.Pipeline]: a pipeline with all the preprocessing steps, in a sequential manner
"""
steps = []
for step_config in steps_config:
# retrieve the name and parameter dictionary of the current steps
step_name, step_params = step_config.items()[0]
# instantiate the pipeline step, and append to the list of steps
pipeline_step = (step_name, hydra.utils.instantiate(step_params))
steps.append(pipeline_step)
return Pipeline(steps)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment