code: def handle_classification_mode(
      y: np.ndarray,
      classification_handling_mode: Optional[str],
      threshold_value: Optional[float] = None,
  ) -> np.ndarray:
      """Handle classification mode.
  
      Transform predictions so that they have the correct classification mode.
  
      Parameters
      ----------
      y: np.ndarray
          Must be of shape `(N, n_tasks, n_classes)`
      classification_handling_mode: str, default None
          DeepChem models by default predict class probabilities for
          classification problems. This means that for a given singletask
          prediction, after shape normalization, the DeepChem prediction will be a
          numpy array of shape `(N, n_classes)` with class probabilities.
          `classification_handling_mode` is a string that instructs this method
          how to handle transforming these probabilities. It can take on the
          following values:
          - None: default value. Pass in `y_pred` directy into `self.metric`.
          - "threshold": Use `threshold_predictions` to threshold `y_pred`. Use
            `threshold_value` as the desired threshold.
          - "threshold-one-hot": Use `threshold_predictions` to threshold `y_pred`
            using `threshold_values`, then apply `to_one_hot` to output.
      threshold_value: float, default None
          If set, and `classification_handling_mode` is "threshold" or
          "threshold-one-hot" apply a thresholding operation to values with this
          threshold. This option isj only sensible on binary classification tasks.
          If float, this will be applied as a binary classification value.
  
      Returns
      -------
      y_out: np.ndarray
          If `classification_handling_mode` is "direct", then of shape `(N, n_tasks, n_classes)`.
          If `classification_handling_mode` is "threshold", then of shape `(N, n_tasks)`.
          If `classification_handling_mode is "threshold-one-hot", then of shape `(N, n_tasks, n_classes)"
      """
      if len(y.shape) != 3:
          raise ValueError("y must be of shape (N, n_tasks, n_classes)")
      N, n_tasks, n_classes = y.shape
      if classification_handling_mode == "direct":
          return y
      elif classification_handling_mode == "threshold":
          thresholded = []
          for task in range(n_tasks):
              task_array = y[:, task, :]
              # Now of shape (N,)
              task_array = threshold_predictions(
                  task_array, threshold_value
              )
              # Now of shape (N, 1)
              task_array = np.expand_dims(task_array, 1)
              thresholded.append(task_array)
          # Returns shape (N, n_tasks)
          return np.concatenate(thresholded, axis=1)
      elif classification_handling_mode == "threshold-one-hot":
          thresholded = []
          for task in range(n_tasks):
              task_array = y[:, task, :]
              # Now of shape (N,)
              task_array = threshold_predictions(
                  task_array, threshold_value
              )
              # Now of shape (N, n_classes)
              task_array = to_one_hot(task_array, n_classes=n_classes)
              # Now of shape (N, 1, n_classes)
              task_array = np.expand_dims(task_array, 1)
              thresholded.append(task_array)
          # Returns shape (N, n_tasks, n_classes)
          return np.concatenate(thresholded, axis=1)
      else:
          raise ValueError(
              "classification_handling_mode must be one of direct, threshold, threshold-one-hot"
          )
  
file_path: deepchem/deepchem/metrics/metric.py
imports: import logging
  from typing import Any, Callable, Optional
  import numpy
  from numpy.typing import ArrayLike
label_desc: Use image node_id 5 for calling a global function with example usage: handle_classification_mode(y, classification_handling_mode, threshold_value) and returns: y, np, np