code: def to_one_hot(y: np.ndarray, n_classes: int = 2) -> np.ndarray:
      """Transforms label vector into one-hot encoding.
  
      Turns y into vector of shape `(N, n_classes)` with a one-hot
      encoding. Assumes that `y` takes values from `0` to `n_classes - 1`.
  
      Parameters
      ----------
      y: np.ndarray
          A vector of shape `(N,)` or `(N, 1)`
      n_classes: int, default 2
          If specified use this as the number of classes. Else will try to
          impute it as `n_classes = max(y) + 1` for arrays and as
          `n_classes=2` for the case of scalars. Note this parameter only
          has value if `mode=="classification"`
  
      Returns
      -------
      np.ndarray
          A numpy array of shape `(N, n_classes)`.
      """
      if len(y.shape) > 2:
          raise ValueError("y must be a vector of shape (N,) or (N, 1)")
      if len(y.shape) == 2 and y.shape[1] != 1:
          raise ValueError("y must be a vector of shape (N,) or (N, 1)")
      if len(np.unique(y)) > n_classes:
          raise ValueError("y has more than n_class unique elements.")
      N = np.shape(y)[0]
      y_hot = np.zeros((N, n_classes))
      y_hot[np.arange(N), y.astype(np.int64)] = 1
      return y_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 6 for calling a global function with example usage: to_one_hot(y, n_classes) and returns: y_hot