Skip to content

Instantly share code, notes, and snippets.

@lorey
Created May 29, 2019 07:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lorey/c14472e68ccf3320277f9e144582dc6e to your computer and use it in GitHub Desktop.
Save lorey/c14472e68ccf3320277f9e144582dc6e to your computer and use it in GitHub Desktop.
Function to flatten hierarchical parameters when training a pandas pipeline
def hierarchical_to_flattened_parameters(parameters_dict):
"""
Flatten an hierarchical dict to an sklearn parameter set.
:param parameters_dict: hierarchical dict
:return: flattened dict
"""
return json_normalize(parameters_dict, sep='__').to_dict(orient='records')[0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment