code: def get_categorical_conf(raw_confs: np.ndarray):
      """
      ICP confidence estimation for categorical targets from raw p-values:
          1.0 minus 2nd highest p-value yields confidence for predicted label.
      :param all_confs: p-value for each class per data point
      :return: confidence for each data point
      """
      if len(raw_confs.shape) == 1:
          raw_confs = np.expand_dims(raw_confs, axis=0)
      if raw_confs.shape[-1] == 1:
          # single-class edge case (only happens if predictor sees just one known label at calibration)
          confs = np.clip(raw_confs[:, 0], 0.0001, 0.9999)
      else:
          second_p = np.sort(raw_confs, axis=1)[:, -2]
          confs = np.clip(np.subtract(1, second_p), 0.0001, 0.9999)
      return confs
  
file_path: lightwood/lightwood/analysis/nc/util.py
imports: from typing import Union, Optional
  import torch
  import numpy
  import pandas
  from torch.nn.functional import softmax
  from type_infer.dtype import dtype
label_desc: Use image node_id 6 for calling a global function with example usage: get_categorical_conf(raw_confs) and returns: confs