{"record":{"id":"253f91a1cef5b532","repo":"keras-team/keras","slug":"invalid-threshold-argument-value-it-should-veri","errorCode":null,"errorMessage":"Invalid `threshold` argument value. It should verify 0 < threshold <= 1. Received: threshold={threshold}","messagePattern":"Invalid `threshold` argument value\\. It should verify 0 < threshold <= 1\\. Received: threshold=(.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/metrics/f_score_metrics.py","lineNumber":107,"sourceCode":"                f\"Received: beta={beta} of type '{type(beta)}'\"\n            )\n        if beta <= 0.0:\n            raise ValueError(\n                \"Invalid `beta` argument value. \"\n                \"It should be > 0. \"\n                f\"Received: beta={beta}\"\n            )\n\n        if threshold is not None:\n            if not isinstance(threshold, float):\n                raise ValueError(\n                    \"Invalid `threshold` argument value. \"\n                    \"It should be a Python float. \"\n                    f\"Received: threshold={threshold} \"\n                    f\"of type '{type(threshold)}'\"\n                )\n            if threshold > 1.0 or threshold <= 0.0:\n                raise ValueError(\n                    \"Invalid `threshold` argument value. \"\n                    \"It should verify 0 < threshold <= 1. \"\n                    f\"Received: threshold={threshold}\"\n                )\n\n        self.average = average\n        self.beta = beta\n        self.threshold = threshold\n        self.axis = None\n        self._built = False\n\n        if self.average != \"micro\":\n            self.axis = 0\n\n    def _build(self, y_true_shape, y_pred_shape):\n        if len(y_pred_shape) != 2 or len(y_true_shape) != 2:\n            raise ValueError(\n                \"FBetaScore expects 2D inputs with shape \"","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/metrics/f_score_metrics.py#L89-L125","documentation":"Raised by FBetaScore's __init__ when threshold is a float outside (0, 1.0], i.e. <= 0.0 or > 1.0. The threshold converts probabilities to hard decisions, so it must lie in that interval.","triggerScenarios":"keras.metrics.FBetaScore(beta=1.0, threshold=1.5); threshold=0.0; -0.5; percent-style values like 50.","commonSituations":"Percent/fraction confusion; not knowing 0.0 is invalid but 1.0 is valid; config typos.","solutions":["Use a value in (0, 1], e.g. 0.5.","Convert percentages: t = pct / 100.0.","For hard 0/1 labels leave threshold=None and supply integer labels."],"exampleFix":"# before\nm = keras.metrics.FBetaScore(beta=1.0, threshold=50)\n\n# after\nm = keras.metrics.FBetaScore(beta=1.0, threshold=0.5)","handlingStrategy":"validation","validationCode":"if threshold is not None and not (0.0 < threshold <= 1.0):\n    raise ValueError(f'threshold must be in (0, 1], got {threshold}')","typeGuard":"def is_valid_threshold(v) -> bool:\n    return v is None or (isinstance(v, float) and 0.0 < v <= 1.0)","tryCatchPattern":null,"preventionTips":["Store thresholds as fractions in configs.","Remember 1.0 is valid, 0.0 is not."],"tags":["keras","metrics","fbeta","threshold","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"}