docstr: Parameters
  ----------
  data
      2-dimensional pandas dataframe or numpy array.
  categorical_columns
      A list of columns indicating categorical variables. Optional if passing a pandas dataframe as inference will
      be used based on dtype 'O'. If passing a numpy array this is compulsory.
  Returns
  -------
  category_map
      A dictionary with keys being the indices of the categorical columns and values being lists of categories for
      that column. Implicitly each category is mapped to the index of its position in the list.
docstr_tok: ["Parameters","--","--","--","--","--","data","2-dimensional","pandas","dataframe","or","numpy","array",".","categorical_columns","A","list","of","columns","indicating","categorical","variables",".","Optional","if","passing","a","pandas","dataframe","as","inference","will","be","used","based","on","dtype","'","O","'",".","If","passing","a","numpy","array","this","is","compulsory",".","Returns","--","--","--","-","category_map","A","dictionary","with","keys","being","the","indices","of","the","categorical","columns","and","values","being","lists","of","categories","for","that","column",".","Implicitly","each","category","is","mapped","to","the","index","of","its","position","in","the","list","."]
code: def gen_category_map(
      input_data: Union[pd.DataFrame, np.ndarray],
      categorical_columns: Union[List[int], List[str], None] = None,
  ) -> Dict[int, list]:
      """
      Parameters
      ----------
      data
          2-dimensional pandas dataframe or numpy array.
      categorical_columns
          A list of columns indicating categorical variables. Optional if passing a pandas dataframe as inference will
          be used based on dtype 'O'. If passing a numpy array this is compulsory.
      Returns
      -------
      category_map
          A dictionary with keys being the indices of the categorical columns and values being lists of categories for
          that column. Implicitly each category is mapped to the index of its position in the list.
      """
  
      if input_data.ndim != 2:
          raise TypeError("Expected a 2-dimensional dataframe or array")
      n_features = input_data.shape[1]
  
      if isinstance(input_data, np.ndarray):
          # if numpy array, we need categorical_columns, otherwise impossible to infer
          if categorical_columns is None:
              raise ValueError(
                  "If passing a numpy array, `categorical_columns` is required"
              )
          elif not all(
              isinstance(ix, int) for ix in categorical_columns
          ):
              raise ValueError(
                  "If passing a numpy array, `categorical_columns` must be a list of integers"
              )
          input_data = pd.DataFrame(input_data)
  
      # infer categorical columns
      if categorical_columns is None:
          try:
              categorical_columns = [
                  i
                  for i in range(n_features)
                  if input_data.iloc[:, i].dtype == "O"
              ]  # NB: 'O'
          except AttributeError:
              raise
  
      # create the map
      category_map = {}
      for col in categorical_columns:
          if not isinstance(col, int):
              col = int(input_data.columns.get_loc(col))
          le = LabelEncoder()
          try:
              _ = le.fit_transform(input_data.iloc[:, col])
          except (AttributeError, IndexError):
              raise
  
          category_map[col] = list(le.classes_)
  
      return category_map
  
file_path: explainx/lib/models/modelprocessor.py
imports: from sklearn.ensemble import RandomForestClassifier, RandomForestRegressor
  import numpy
  import pandas
  from sklearn.preprocessing import LabelEncoder
  from typing import Dict, List, Union
  from sklearn.impute import SimpleImputer
  from explainx.lib.utils import is_classification
label_desc: Use image node_id 3 for calling the ModelProcessor obj's underlying member method code with example usage: obj.gen_category_map(input_data, categorical_columns) and returns: category_map