code: def rank_n_accuracy(y_true, y_prob_mat, n=0.33):
      """
      Compute how often the true label is one of the top n predicted classes
      for each training example.
      If n is an integer, consider the top n predictions for each example.
      If n is a float, it represents a proportion of the top predictions.
      This metric is only really useful when the total number of classes is large.
      """
      n_classes = y_prob_mat.shape[1]
      if n < 1:
          # round to nearest int before casting
          n = int(round(n_classes * n))
  
      # sort the rankings in descending order, then take the top n
      rankings = np.argsort(-y_prob_mat)
      rankings = rankings[:, :n]
  
      num_samples = len(y_true)
      correct_sample_count = 0.0  # force floating point math
  
      for i in range(num_samples):
          if y_true[i] in rankings[i, :]:
              correct_sample_count += 1
  
      return int(correct_sample_count / num_samples)
  
file_path: ATM/atm/metrics.py
imports: from __future__ import absolute_import, division, unicode_literals
  from builtins import range
  import numpy
  import pandas
  from sklearn.metrics import accuracy_score, average_precision_score, cohen_kappa_score, f1_score, matthews_corrcoef, precision_recall_curve, roc_auc_score, roc_curve
  from sklearn.model_selection import StratifiedKFold
  from atm.constants import METRICS_BINARY, METRICS_MULTICLASS, N_FOLDS_DEFAULT, Metrics
label_desc: Use image node_id 1 for calling a global function with example usage: rank_n_accuracy(y_true, y_prob_mat, n) and returns: int