{"record":{"id":"4a03bd894c37426c","repo":"keras-team/keras","slug":"argument-precision-must-be-in-the-range-0-1","errorCode":null,"errorMessage":"Argument `precision` must be in the range [0, 1]. Received: precision={precision}","messagePattern":"Argument `precision` must be in the range \\[0, 1\\]\\. Received: precision=(.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/metrics/confusion_metrics.py","lineNumber":1032,"sourceCode":"\n    ```python\n    model.compile(\n        optimizer='sgd',\n        loss='binary_crossentropy',\n        metrics=[keras.metrics.RecallAtPrecision(precision=0.8)])\n    ```\n    \"\"\"\n\n    def __init__(\n        self,\n        precision,\n        num_thresholds=200,\n        class_id=None,\n        name=None,\n        dtype=None,\n    ):\n        if precision < 0 or precision > 1:\n            raise ValueError(\n                \"Argument `precision` must be in the range [0, 1]. \"\n                f\"Received: precision={precision}\"\n            )\n        self.precision = precision\n        self.num_thresholds = num_thresholds\n        super().__init__(\n            value=precision,\n            num_thresholds=num_thresholds,\n            class_id=class_id,\n            name=name,\n            dtype=dtype,\n        )\n\n    def result(self):\n        recalls = ops.divide_no_nan(\n            self.true_positives,\n            ops.add(self.true_positives, self.false_negatives),\n        )","sourceCodeStart":1014,"sourceCodeEnd":1050,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/metrics/confusion_metrics.py#L1014-L1050","documentation":"Raised by keras.metrics.RecallAtPrecision's __init__ when the precision argument is outside [0, 1]. Precision is a probability-like score; Keras validates the range at construction time.","triggerScenarios":"keras.metrics.RecallAtPrecision(precision=1.05); passing 99 (percent); a computed tp/(tp+fp) that is unclamped above 1.","commonSituations":"Percent/fraction confusion; unclamped ratios; config typos.","solutions":["Pass a fraction in [0, 1], e.g. precision=0.99.","Clamp computed values: min(max(v, 0.0), 1.0).","Validate config entries before building the model."],"exampleFix":"# before\nm = keras.metrics.RecallAtPrecision(precision=99)\n\n# after\nm = keras.metrics.RecallAtPrecision(precision=0.99)","handlingStrategy":"validation","validationCode":"if not (0.0 <= precision <= 1.0):\n    raise ValueError(f'precision must be in [0,1], got {precision}')","typeGuard":"def is_probability(v) -> bool:\n    return isinstance(v, (int, float)) and 0.0 <= v <= 1.0","tryCatchPattern":null,"preventionTips":["Clamp tp/(tp+fp) style ratios to [0,1].","Keep percent-to-fraction conversion in one place."],"tags":["keras","metrics","precision","range-validation"],"backgroundTag":"probability-out-of-range","analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}