{"record":{"id":"347782122b9d81b7","repo":"tensorflow/models","slug":"num-class-must-be-a-positive-integer","errorCode":null,"errorMessage":"num_class must be a positive integer.","messagePattern":"num_class must be a positive integer\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"official/projects/yt8m/eval_utils/mean_average_precision_calculator.py","lineNumber":61,"sourceCode":"\nclass MeanAveragePrecisionCalculator(object):\n  \"\"\"This class is to calculate mean average precision.\"\"\"\n\n  def __init__(self, num_class, filter_empty_classes=True, top_n=None):\n    \"\"\"Construct a calculator to calculate the (macro) average precision.\n\n    Args:\n      num_class: A positive Integer specifying the number of classes.\n      filter_empty_classes: whether to filter classes without any positives.\n      top_n: A positive Integer specifying the average precision at n, or None\n        to use all provided data points.\n\n    Raises:\n      ValueError: An error occurred when num_class is not a positive integer;\n      or the top_n_array is not a list of positive integers.\n    \"\"\"\n    if not isinstance(num_class, int) or num_class < 1:\n      raise ValueError(\"num_class must be a positive integer.\")\n\n    self._ap_calculators = []  # member of AveragePrecisionCalculator\n    self._num_class = num_class  # total number of classes\n    self._filter_empty_classes = filter_empty_classes\n    for _ in range(num_class):\n      self._ap_calculators.append(\n          average_precision_calculator.AveragePrecisionCalculator(top_n=top_n))\n\n  def accumulate(self, predictions, actuals, num_positives=None):\n    \"\"\"Accumulate the predictions and their ground truth labels.\n\n    Args:\n      predictions: A list of lists storing the prediction scores. The outer\n        dimension corresponds to classes.\n      actuals: A list of lists storing the ground truth labels. The dimensions\n        should correspond to the predictions input. Any value larger than 0 will\n        be treated as positives, otherwise as negatives.\n      num_positives: If provided, it is a list of numbers representing the","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/projects/yt8m/eval_utils/mean_average_precision_calculator.py#L43-L79","documentation":"Error \"num_class must be a positive integer.\" thrown in tensorflow/models.","triggerScenarios":"Thrown at official/projects/yt8m/eval_utils/mean_average_precision_calculator.py:61 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e006f5f0d534913e49c1f1dae87364039fa607e2","analyzedAt":"2026-08-24T14:09:15.576Z","schemaVersion":2},"datasetVersion":"2026-08-24T17:17:21.512Z"}