class_docstr: Wrapper class for computing user-defined metrics.
  
  The `Metric` class provides a wrapper for standardizing the API
  around different classes of metrics that may be useful for DeepChem
  models. The implementation provides a few non-standard conveniences
  such as built-in support for multitask and multiclass metrics.
  
  There are a variety of different metrics this class aims to support.
  Metrics for classification and regression that assume that values to
  compare are scalars are supported.
  
  At present, this class doesn't support metric computation on models
  which don't present scalar outputs. For example, if you have a
  generative model which predicts images or molecules, you will need
  to write a custom evaluation and metric setup.
docstr: Compute a metric value.
  
  Parameters
  ----------
  y_true: ArrayLike
      True values array. This array must be of shape `(N,
      n_classes)` if classification and `(N,)` if regression.
  y_pred: ArrayLike
      Predictions array. This array must be of shape `(N, n_classes)`
      if classification and `(N,)` if regression.
  w: ArrayLike, default None
      Sample weight array. This array must be of shape `(N,)`
  n_samples: int, default None (DEPRECATED)
      The number of samples in the dataset. This is `N`. This argument is
      ignored.
  use_sample_weights: bool, default False
      If set, use per-sample weights `w`.
  kwargs: dict
      Will be passed on to self.metric
  
  Returns
  -------
  metric_value: float
      The computed value of the metric.
docstr_tok: ["Compute","a","metric","value",".","Parameters","--","--","--","--","--","y_true",":","ArrayLike","True","values","array",".","This","array","must","be","of","shape","`","(","N",",","n_classes",")","`","if","classification","and","`","(","N",",",")","`","if","regression",".","y_pred",":","ArrayLike","Predictions","array",".","This","array","must","be","of","shape","`","(","N",",","n_classes",")","`","if","classification","and","`","(","N",",",")","`","if","regression",".","w",":","ArrayLike",",","default","None","Sample","weight","array",".","This","array","must","be","of","shape","`","(","N",",",")","`","n_samples",":","int",",","default","None","(","DEPRECATED",")","The","number","of","samples","in","the","dataset",".","This","is","`","N","`",".","This","argument","is","ignored",".","use_sample_weights",":","bool",",","default","False","If","set",",","use","per-sample","weights","`","w","`",".","kwargs",":","dict","Will","be","passed","on","to","self.metric","Returns","--","--","--","-","metric_value",":","float","The","computed","value","of","the","metric","."]
code: def compute_singletask_metric(
      self,
      y_true: ArrayLike,
      y_pred: ArrayLike,
      w: Optional[ArrayLike] = None,
      n_samples: Optional[int] = None,
      use_sample_weights: bool = False,
      **kwargs,
  ) -> float:
      """Compute a metric value.
  
      Parameters
      ----------
      y_true: ArrayLike
          True values array. This array must be of shape `(N,
          n_classes)` if classification and `(N,)` if regression.
      y_pred: ArrayLike
          Predictions array. This array must be of shape `(N, n_classes)`
          if classification and `(N,)` if regression.
      w: ArrayLike, default None
          Sample weight array. This array must be of shape `(N,)`
      n_samples: int, default None (DEPRECATED)
          The number of samples in the dataset. This is `N`. This argument is
          ignored.
      use_sample_weights: bool, default False
          If set, use per-sample weights `w`.
      kwargs: dict
          Will be passed on to self.metric
  
      Returns
      -------
      metric_value: float
          The computed value of the metric.
      """
      if n_samples is not None:
          logger.warning(
              "n_samples is a deprecated argument which is ignored."
          )
      # Attempt to convert both into the same type
      y_true_arr = np.asarray(y_true)
      y_pred_arr = np.asarray(y_pred)
      if self.mode == "regression":
          if (
              len(y_true_arr.shape) != 1
              or len(y_pred_arr.shape) != 1
              or y_true_arr.shape != y_pred_arr.shape
          ):
              raise ValueError(
                  "For regression metrics, y_true and y_pred must both be of shape (N,)"
              )
      elif self.mode == "classification":
          pass
          # if len(y_true.shape) != 2 or len(y_pred.shape) != 2 or y_true.shape != y_pred.shape:
          # raise ValueError("For classification metrics, y_true and y_pred must both be of shape (N, n_classes)")
      else:
          raise ValueError(
              "Only classification and regression are supported for metrics calculations."
          )
      if use_sample_weights:
          metric_value = self.metric(
              y_true_arr, y_pred_arr, sample_weight=w, **kwargs
          )
      else:
          metric_value = self.metric(y_true_arr, y_pred_arr, **kwargs)
      return metric_value
  
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 3 for calling the Metric obj's underlying member method code with example usage: obj.compute_singletask_metric(y_true, y_pred, w, n_samples, use_sample_weights) and returns: metric_value