{"record":{"id":"8843612fb1874ba9","repo":"keras-team/keras","slug":"invalid-beta-argument-value-it-should-be-a-pyth","errorCode":null,"errorMessage":"Invalid `beta` argument value. It should be a Python float. Received: beta={beta} of type '{type(beta)}'","messagePattern":"Invalid `beta` argument value\\. It should be a Python float\\. Received: beta=(.+?) of type '(.+?)'","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/metrics/f_score_metrics.py","lineNumber":86,"sourceCode":"        average=None,\n        beta=1.0,\n        threshold=None,\n        name=\"fbeta_score\",\n        dtype=None,\n    ):\n        super().__init__(name=name, dtype=dtype)\n        # Metric should be maximized during optimization.\n        self._direction = \"up\"\n\n        if average not in (None, \"micro\", \"macro\", \"weighted\"):\n            raise ValueError(\n                \"Invalid `average` argument value. Expected one of: \"\n                \"{None, 'micro', 'macro', 'weighted'}. \"\n                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)}'\"","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/metrics/f_score_metrics.py#L68-L104","documentation":"Raised by FBetaScore's __init__ when beta is not a Python float. Keras enforces the type strictly, so ints like 1 or 2 raise this even though they look numeric.","triggerScenarios":"keras.metrics.FBetaScore(beta=1) (int, not 1.0); beta parsed from JSON/YAML as int; numpy floats or tf.Variable.","commonSituations":"Writing beta=1 or beta=2 as integers (the classic F1 case); config files storing 2 instead of 2.0.","solutions":["Write beta with a decimal point: beta=1.0, beta=2.0.","Coerce config values: float(cfg['beta']).","Note keras.metrics.F1Score is a shortcut for beta=1.0."],"exampleFix":"# before\nm = keras.metrics.FBetaScore(beta=1, average='macro')\n\n# after\nm = keras.metrics.FBetaScore(beta=1.0, average='macro')\n# or simply\nm = keras.metrics.F1Score(average='macro')","handlingStrategy":"type-guard","validationCode":"beta = float(beta)","typeGuard":"def is_float_beta(v) -> bool:\n    return isinstance(v, float)","tryCatchPattern":null,"preventionTips":["Always write beta with a decimal point (1.0, 2.0).","Coerce numeric config values with float() at load."],"tags":["keras","metrics","fbeta","type-validation"],"backgroundTag":"wrong-argument-type","analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}