code: def threshold_predictions(
      y: np.ndarray, threshold: Optional[float] = None
  ) -> np.ndarray:
      """Threshold predictions from classification model.
  
      Parameters
      ----------
      y: np.ndarray
          Must have shape `(N, n_classes)` and be class probabilities.
      threshold: float, default None
          The threshold probability for the positive class. Note that this
          threshold will only be applied for binary classifiers (where
          `n_classes==2`). If specified for multiclass problems, or if
          `threshold` is None, the threshold is ignored and argmax(y) is
          returned.
  
      Returns
      -------
      y_out: np.ndarray
          A numpy array of shape `(N,)` with class predictions as integers ranging from 0
          to `n_classes-1`.
      """
      if not isinstance(y, np.ndarray) or not len(y.shape) == 2:
          raise ValueError(
              "y must be a ndarray of shape (N, n_classes)"
          )
      N = y.shape[0]
      n_classes = y.shape[1]
      if n_classes != 2 or threshold is None:
          return np.argmax(y, axis=1)
      else:
          return np.where(y[:, 1] >= threshold, np.ones(N), np.zeros(N))
  
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 1 for calling a global function with example usage: threshold_predictions(y, threshold) and returns: np, np