code: def retrieve_onehot_value(
      X, encoded_col, onehot_cols, not_encoded="NOT_ENCODED", sep="_"
  ):
      """
      Reverses a onehot encoding.
  
      i.e. Finds the column name starting with encoded_col_ that has a value of 1.
          if no such column exists (e.g. they are all 0), then return 'NOT_ENCODED'
  
      Args:
          X (pd.DataFrame): dataframe from which to retrieve onehot column
          encoded_col (str): Name of the encoded col (e.g. 'Sex')
          onehot_cols (list): list of onehot cols, e.g. ['Sex_female', 'Sex_male']
          sep (str): seperator between category and value, e.g. '_' for Sex_Male.
  
      Returns:
          pd.Series with categories. If no category is found, coded as "NOT_ENCODED".
      """
      feature_value = np.argmax(X[onehot_cols].values, axis=1)
  
      # if not a single 1 then encoded feature must have been dropped
      feature_value[np.max(X[onehot_cols].values, axis=1) == 0] = -1
      if all([col.startswith(col + "_") for col in onehot_cols]):
          mapping = {-1: encoded_col + not_encoded}
      else:
          mapping = {-1: not_encoded}
  
      mapping.update({i: col for i, col in enumerate(onehot_cols)})
      return pd.Series(feature_value).map(mapping)
  
imports: from functools import partial
  import re
  from collections import Counter
  from typing import List, Union
  import warnings
  import numpy
  import pandas
  from pandas.api.types import is_numeric_dtype, is_categorical_dtype
  from dtreeviz.trees import ShadowDecTree
  from sklearn.metrics import make_scorer
  from sklearn.base import clone
  from sklearn.pipeline import Pipeline
  from sklearn.model_selection import KFold, StratifiedKFold
  from joblib import Parallel, delayed
label_desc: Use image node_id 9 for calling a global function with example usage: retrieve_onehot_value(X, encoded_col, onehot_cols, not_encoded, sep) and returns: pd