code: def eval_accuracy_from_scores(
      actual_anomalies: Union[TimeSeries, Sequence[TimeSeries]],
      anomaly_score: Union[TimeSeries, Sequence[TimeSeries]],
      window: Union[int, Sequence[int]] = 1,
      metric: str = "AUC_ROC",
  ) -> Union[float, Sequence[float], Sequence[Sequence[float]]]:
      """Scores the results against true anomalies.
  
      `actual_anomalies` and `anomaly_score` must have the same shape.
      `actual_anomalies` must be binary and have values belonging to the two classes (0 and 1).
  
      If one series is given for `actual_anomalies` and `anomaly_score` contains more than
      one series, the function will consider `actual_anomalies` as the ground truth anomalies for
      all scores in `anomaly_score`.
  
      Parameters
      ----------
      actual_anomalies
          The ground truth of the anomalies (1 if it is an anomaly and 0 if not).
      anomaly_score
          Series indicating how anomoulous each window of size w is.
      window
          Integer value indicating the number of past samples each point represents
          in the anomaly_score. The parameter will be used by the function
          ``_window_adjustment_anomalies()`` to transform actual_anomalies.
          If a list is given. the length must match the number of series in anomaly_score
          and actual_anomalies. If only one window is given, the value will be used for every
          series in anomaly_score and actual_anomalies.
      metric
          Optionally, Scoring function to use. Must be one of "AUC_ROC" and "AUC_PR".
          Default: "AUC_ROC"
  
      Returns
      -------
      Union[float, Sequence[float], Sequence[Sequence[float]]]
          Score of the anomalies score prediction
              * ``float`` if `anomaly_score` is a univariate series (dimension=1).
              * ``Sequence[float]``
  
                  * if `anomaly_score` is a multivariate series (dimension>1),
                    returns one value per dimension.
                  * if `anomaly_score` is a sequence of univariate series, returns one
                    value per series
              * ``Sequence[Sequence[float]]`` if `anomaly_score` is a sequence of
                multivariate series. Outer Sequence is over the sequence input, and the inner
                Sequence is over the dimensions of each element in the sequence input.
      """
  
      raise_if_not(
          metric in {"AUC_ROC", "AUC_PR"},
          "Argument `metric` must be one of 'AUC_ROC', 'AUC_PR'",
      )
      metric_fn = (
          roc_auc_score
          if metric == "AUC_ROC"
          else average_precision_score
      )
  
      list_actual_anomalies, list_anomaly_scores, list_window = (
          _to_list(actual_anomalies),
          _to_list(anomaly_score),
          _to_list(window),
      )
  
      if (
          len(list_actual_anomalies) == 1
          and len(list_anomaly_scores) > 1
      ):
          list_actual_anomalies = list_actual_anomalies * len(
              list_anomaly_scores
          )
  
      _assert_same_length(list_actual_anomalies, list_anomaly_scores)
  
      if len(list_window) == 1:
          list_window = list_window * len(actual_anomalies)
      else:
          raise_if_not(
              len(list_window) == len(list_actual_anomalies),
              "The list of windows must be the same length as the list of `anomaly_score` and"
              + " `actual_anomalies`. There must be one window value for each series."
              + f" Found length {len(list_window)}, expected {len(list_actual_anomalies)}.",
          )
  
      sol = []
      for idx, (s_anomalies, s_score) in enumerate(
          zip(list_actual_anomalies, list_anomaly_scores)
      ):
          _assert_binary(s_anomalies, "actual_anomalies")
  
          sol.append(
              _eval_accuracy_from_data(
                  s_anomalies,
                  s_score,
                  list_window[idx],
                  metric_fn,
                  metric,
              )
          )
  
      if len(sol) == 1 and not isinstance(anomaly_score, Sequence):
          return sol[0]
      else:
          return sol
  
file_path: darts/darts/ad/utils.py
imports: from typing import Sequence, Tuple, Union
  import matplotlib.pyplot
  import numpy
  from sklearn.metrics import accuracy_score, average_precision_score, f1_score, precision_score, recall_score, roc_auc_score
  from darts import TimeSeries
  from darts.logging import get_logger, raise_if, raise_if_not
label_desc: Use image node_id 2 for calling a global function with example usage: eval_accuracy_from_scores(actual_anomalies, anomaly_score, window, metric) and returns: sol, sol