code: def precision_score(y_true, y_pred, sample_weight=None):
      """Computes the precision scores for two arrays.
  
      Parameters
      ----------
      y_true : array-like, 1-D
          The actual categories.
      y_pred : array-like, 1-D
          The predicted categories.
      sample_weight : array-like, 1-D
          The sample weight.
  
      Returns
      -------
      precision : `dict`
          The precision score for different categories.
          The keys are the categories, and the values are the precisions.
      """
      actual_category = pd.unique(y_true)
      pred_category = pd.unique(y_pred)
      labels = pd.unique(
          np.concatenate([actual_category, pred_category])
      )
      precisions_array = metrics.precision_score(
          y_true=y_true,
          y_pred=y_pred,
          average=None,
          labels=labels,
          sample_weight=sample_weight,
          zero_division=0,
      )
      precisions = {}
      for label, precision in zip(labels, precisions_array):
          precisions[label] = precision
      return precisions
  
imports: import functools
  import warnings
  from typing import Optional
  from typing import Union
  import numpy
  import pandas
  from sklearn import metrics
  from greykite.detection.common.ad_evaluation_utils import compute_range_based_score
  from greykite.detection.common.ad_evaluation_utils import prepare_anomaly_ranges
label_desc: Use image node_id 2 for calling a global function with example usage: precision_score(y_true, y_pred, sample_weight) and returns: precisions