{"record":{"id":"3039b1eac9f44c8f","repo":"keras-team/keras","slug":"invalid-threshold-argument-value-it-should-be-a","errorCode":null,"errorMessage":"Invalid `threshold` argument value. It should be a Python float. Received: threshold={threshold} of type '{type(threshold)}'","messagePattern":"Invalid `threshold` argument value\\. It should be a Python float\\. Received: threshold=(.+?) of type '(.+?)'","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/metrics/f_score_metrics.py","lineNumber":100,"sourceCode":"                f\"Received: average={average}\"\n            )\n\n        if not isinstance(beta, float):\n            raise ValueError(\n                \"Invalid `beta` argument value. \"\n                \"It should be a Python float. \"\n                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","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/metrics/f_score_metrics.py#L82-L118","documentation":"Raised by FBetaScore's __init__ when threshold is not None and not a Python float. The optional binarizing threshold must be an explicit float; ints like 0 or 1 are rejected.","triggerScenarios":"keras.metrics.FBetaScore(beta=1.0, threshold=1); threshold loaded from config as int; numpy float64 values.","commonSituations":"Setting threshold=0 or 1 as ints; JSON configs parsing to int; forgetting the decimal point.","solutions":["Pass a float: threshold=0.5.","Coerce: threshold=float(cfg['threshold']).","Leave threshold as None (default) when no binarization is wanted."],"exampleFix":"# before\nm = keras.metrics.FBetaScore(beta=1.0, threshold=1)\n\n# after\nm = keras.metrics.FBetaScore(beta=1.0, threshold=0.5)  # or omit threshold","handlingStrategy":"type-guard","validationCode":"threshold = None if threshold is None else float(threshold)","typeGuard":"def is_float_or_none(v) -> bool:\n    return v is None or isinstance(v, float)","tryCatchPattern":null,"preventionTips":["Write thresholds with a decimal point.","Coerce config ints with float() before use."],"tags":["keras","metrics","fbeta","threshold","type-validation"],"backgroundTag":"wrong-argument-type","analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}