code: def compute_eval_from_predictions(
      examples_file: PathOrStr,
      predictions_file: PathOrStr,
      metric_names: List[str],
      prediction_method: Optional[str] = None,
  ) -> Dict[str, float]:
      """
      Compute evaluation metrics from prediction files after running an experiment.
  
      Parameters
      ----------
      examples_file: :class:`skll.types.PathOrStr`
          Path to a SKLL examples file (in .jsonlines or other format).
      predictions_file: :class:`skll.types.PathOrStr`
          Path to a SKLL predictions output TSV file with id and prediction column names.
      metric_names: List[str]
          A list of SKLL metric names (e.g., ``["pearson", "unweighted_kappa"]``).
      prediction_method: Optional[str], default=None
          Indicates how to get a single class prediction from the probabilities.
          Currently supported options are ``"highest"``, which selects the class
          with the highest probability, and ``"expected_value"``, which calculates
          an expected value over integer classes and rounds to the nearest int.
          If predictions file does not contain probabilities, this should be set
          to ``None``.
  
      Returns
      -------
      Dict[str, float]
          Mapping of metrics names to corresponding values.
  
      Raises
      ------
      ValueError
          If the requested prediction method is ``"expected_value"`` but
          the class names can't be converted to ints.
      """
      # convert the examples file and predictions file to a Path
      examples_file = Path(examples_file)
      predictions_file = Path(predictions_file)
  
      # read gold standard labels
      data = Reader.for_path(examples_file).read()
      if data.labels is not None:
          gold = dict(zip(data.ids, data.labels))
  
      # read predictions
      pred = {}
      with open(predictions_file) as pred_file:
          reader = csv.reader(pred_file, dialect=csv.excel_tab)
          header = next(reader)
  
          # If there are more than two columns, assume column 0 contains the ids, and
          # columns 1-n contain class probabilities. Convert them to a class prediction
          # using the specified `method`.
          classes: Union[List[int], List[str]]
          if len(header) > 2:
              classes = [c for c in header[1:] if c]
              if prediction_method is None:
                  prediction_method = "highest"
                  logger.info(
                      "No prediction method specified. Using 'highest'."
                  )
              if prediction_method == "expected_value":
                  try:
                      classes = [int(c) for c in classes]
                  except ValueError as e:
                      raise e
              for row in reader:
                  probabilities = [safe_float(p) for p in row[1:]]
                  prediction = get_prediction_from_probabilities(
                      classes, probabilities, prediction_method  # type: ignore
                  )
                  pred[row[0]] = safe_float(prediction)
          else:
              if prediction_method is not None:
                  logger.warning(
                      "A prediction method was provided, but the "
                      "predictions file doesn't contain "
                      "probabilities. Ignoring prediction method "
                      f"'{prediction_method}'."
                  )
  
              for row in reader:
                  pred[row[0]] = safe_float(row[1])
  
      # make a sorted list of example ids in order to match up
      # labels and predictions
      if set(gold.keys()) != set(pred.keys()):
          raise ValueError(
              "The example and prediction IDs do not match."
          )
      example_ids = sorted(gold.keys())
  
      res = {}
      for metric_name in metric_names:
          score = use_score_func(
              metric_name,
              np.array([gold[ex_id] for ex_id in example_ids]),
              np.array([pred[ex_id] for ex_id in example_ids]),
          )
          res[metric_name] = score
      return res
  
file_path: skll/skll/utils/commandline/compute_eval_from_predictions.py
imports: import argparse
  import csv
  import logging
  from pathlib import Path
  from typing import Dict, List, Optional, Union
  import numpy
  from skll.data import Reader, safe_float
  from skll.metrics import use_score_func
  from skll.types import PathOrStr
  from skll.version import __version__
label_desc: Use image node_id 2 for calling a global function with example usage: compute_eval_from_predictions(examples_file, predictions_file, metric_names, prediction_method) and returns: res