code: def confusion_matrix(y_true, y_pred, sample_weight=None):
      """Computes the confusion matrix 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
      -------
      confusion_matrix : `pandas.DataFrame`
          The confusion matrix.
      """
      actual_category = pd.unique(y_true)
      pred_category = pd.unique(y_pred)
      all_category = pd.unique(
          np.concatenate([actual_category, pred_category])
      )
      matrix = metrics.confusion_matrix(
          y_true=y_true,
          y_pred=y_pred,
          labels=all_category,
          sample_weight=sample_weight,
      )
      matrix = pd.DataFrame(matrix)
      matrix.index = pd.MultiIndex.from_arrays(
          [["Actual"] * len(all_category), matrix.index]
      )
      matrix.columns = pd.MultiIndex.from_arrays(
          [["Pred"] * len(all_category), matrix.columns]
      )
      return matrix
  
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 7 for calling a global function with example usage: confusion_matrix(y_true, y_pred, sample_weight) and returns: matrix