code: def set_conf_range(
      X: pd.DataFrame,
      icp,
      target_type: dtype,
      analysis_info: dict,
      positive_domain: bool = False,
      std_tol: int = 1,
      group: str = "__default",
      significance: Optional[float] = None,
  ):
      """
      Automatically sets confidence level for numerical and categorical tasks.
  
      :param X: Validation data.
      :param icp: Inductive conformal predictor that sets the confidence level. Either IcpClassifier or IcpRegressor.
      :param target_type: dtype of the target column.
      :param analysis_info:
      :param positive_domain: Flag that indicates whether target is expected to be a positive number.
      :param std_tol: Tolerance for automatic confidence level selection; bigger tolerance means higher confidence, in general.
      :param group: For tasks with multiple different target groups (where each may have a different std_dev), indicates what group is being considered.
      :param significance: Desired confidence level. Can be preset (0 < x <= 0.99)
  
      :return: set confidence plus predictions regions (for numerical tasks) or pvalues (for categorical tasks).
      """  # noqa
      # numerical
      if target_type in (dtype.integer, dtype.float, dtype.quantity):
          # ICP gets all possible bounds (shape: (B, 2, 99))
          all_ranges = icp.predict(X.values)
  
          # iterate over confidence levels until spread >= a multiplier of the dataset stddev
          if significance is not None:
              conf = int(100 * (1 - significance))
              return significance, all_ranges[:, :, conf]
          else:
              for tol in [std_tol, std_tol + 1, std_tol + 2]:
                  for significance in range(99):
                      ranges = all_ranges[:, :, significance]
                      spread = np.mean(ranges[:, 1] - ranges[:, 0])
                      tolerance = (
                          analysis_info["df_target_stddev"][group] * tol
                      )
  
                      if spread <= tolerance:
                          confidence = (99 - significance) / 100
                          if positive_domain:
                              ranges[ranges < 0] = 0
                          return confidence, ranges
              else:
                  ranges = all_ranges[:, :, 0]
                  if positive_domain:
                      ranges[ranges < 0] = 0
                  return 0.9901, ranges
  
      # time series
      elif target_type in (dtype.num_array, dtype.num_tsarray):
          pass
  
      # categorical
      elif target_type in (
          dtype.binary,
          dtype.categorical,
          dtype.cat_array,
          dtype.cat_tsarray,
      ):
          pvals = icp.predict(
              X.values
          )  # p-values at which each class is included in the predicted set
          conf = get_categorical_conf(pvals)
          return conf, pvals
  
      # default
      return 0.005, np.zeros((X.shape[0], 2))
  
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 3 for calling a global function with example usage: set_conf_range(X, icp, target_type, analysis_info, positive_domain, std_tol, group, significance) and returns: int,  np, significance,  all_ranges, int,  ranges, conf,  pvals, confidence,  ranges