code: def precision_n_scores(y, y_pred, n=None):
      """Utility function to calculate precision @ rank n.
  
      Parameters
      ----------
      y : list or numpy array of shape (n_samples,)
          The ground truth. Binary (0: inliers, 1: outliers).
  
      y_pred : list or numpy array of shape (n_samples,)
          The raw outlier scores as returned by a fitted model.
  
      n : int, optional (default=None)
          The number of outliers. if not defined, infer using ground truth.
  
      Returns
      -------
      precision_at_rank_n : float
          Precision at rank n score.
  
      """
  
      # turn raw prediction decision scores into binary labels
      y_pred = get_label_n(y, y_pred, n)
  
      # enforce formats of y and labels_
      y = column_or_1d(y)
      y_pred = column_or_1d(y_pred)
  
      return precision_score(y, y_pred)
  
imports: from __future__ import division
  from __future__ import print_function
  import numbers
  import numpy
  import sklearn
  from numpy import percentile
  from sklearn.metrics import precision_score
  from sklearn.preprocessing import StandardScaler
  from sklearn.utils import check_array
  from sklearn.utils import check_consistent_length
  from sklearn.utils import check_random_state
  from sklearn.utils import column_or_1d
  from sklearn.utils.random import sample_without_replacement
label_desc: Use image node_id 5 for calling a global function with example usage: precision_n_scores(y, y_pred, n) and returns: precision_score