{"record":{"id":"1334f547c0af268e","repo":"keras-team/keras","slug":"argument-num-thresholds-must-be-an-integer-1","errorCode":null,"errorMessage":"Argument `num_thresholds` must be an integer > 1. Received: num_thresholds={num_thresholds}","messagePattern":"Argument `num_thresholds` must be an integer > 1\\. Received: num_thresholds=(.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/metrics/confusion_metrics.py","lineNumber":1235,"sourceCode":"                \"Invalid `summation_method` \"\n                f'argument value \"{summation_method}\". '\n                f\"Expected one of: {list(metrics_utils.AUCSummationMethod)}\"\n            )\n\n        # Update properties.\n        self._init_from_thresholds = thresholds is not None\n        if thresholds is not None:\n            # If specified, use the supplied thresholds.\n            self.num_thresholds = len(thresholds) + 2\n            thresholds = sorted(thresholds)\n            self._thresholds_distributed_evenly = (\n                metrics_utils.is_evenly_distributed_thresholds(\n                    np.array([0.0] + thresholds + [1.0])\n                )\n            )\n        else:\n            if num_thresholds <= 1:\n                raise ValueError(\n                    \"Argument `num_thresholds` must be an integer > 1. \"\n                    f\"Received: num_thresholds={num_thresholds}\"\n                )\n\n            # Otherwise, linearly interpolate (num_thresholds - 2) thresholds in\n            # (0, 1).\n            self.num_thresholds = num_thresholds\n            thresholds = [\n                (i + 1) * 1.0 / (num_thresholds - 1)\n                for i in range(num_thresholds - 2)\n            ]\n            self._thresholds_distributed_evenly = True\n\n        # Add an endpoint \"threshold\" below zero and above one for either\n        # threshold method to account for floating point imprecisions.\n        self._thresholds = np.array(\n            [0.0 - backend.epsilon()] + thresholds + [1.0 + backend.epsilon()]\n        )","sourceCodeStart":1217,"sourceCodeEnd":1253,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/metrics/confusion_metrics.py#L1217-L1253","documentation":"Raised by keras.metrics.AUC's __init__ when num_thresholds <= 1 and no explicit thresholds list was given. AUC needs at least two thresholds to interpolate the curve.","triggerScenarios":"keras.metrics.AUC(num_thresholds=1) or 0; intending a single operating point; config values derived from len(list) that evaluate to 1.","commonSituations":"Sweeps starting at 1; misunderstanding that internal endpoints 0.0/1.0 are added so num_thresholds must exceed 1; legacy TF 1.x code.","solutions":["Set num_thresholds >= 2 (default 200).","For a single decision threshold use keras.metrics.Precision/Recall with threshold=... instead of AUC.","Pass thresholds=[...] explicitly when you need specific cutoffs."],"exampleFix":"# before\nauc = keras.metrics.AUC(num_thresholds=1)\n\n# after\nauc = keras.metrics.AUC(num_thresholds=200)\n# or explicit cutoffs:\nauc = keras.metrics.AUC(thresholds=[0.1, 0.3, 0.5, 0.7, 0.9])","handlingStrategy":"validation","validationCode":"if thresholds is None and (not isinstance(num_thresholds, int) or num_thresholds <= 1):\n    raise ValueError('num_thresholds must be an integer > 1')","typeGuard":"def is_valid_auc_thresholds(nt) -> bool:\n    return isinstance(nt, int) and nt > 1","tryCatchPattern":null,"preventionTips":["Start num_thresholds sweeps at 2.","Use an explicit thresholds list when you need specific cutoffs."],"tags":["keras","metrics","auc","num-thresholds"],"backgroundTag":"invalid-argument-range","analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}