{"record":{"id":"b39ea6f2c8a6bdb4","repo":"keras-team/keras","slug":"invalid-average-argument-value-expected-one-of","errorCode":null,"errorMessage":"Invalid `average` argument value. Expected one of: {None, 'micro', 'macro', 'weighted'}. Received: average={average}","messagePattern":"Invalid `average` argument value\\. Expected one of: (.+?)\\. Received: average=(.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/metrics/f_score_metrics.py","lineNumber":79,"sourceCode":"    >>> result = metric.result()\n    >>> result\n    [0.3846154 , 0.90909094, 0.8333334 ]\n    \"\"\"\n\n    def __init__(\n        self,\n        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","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/metrics/f_score_metrics.py#L61-L97","documentation":"Raised by FBetaScore's __init__ when average is not one of None, 'micro', 'macro', 'weighted'. These are the only averaging strategies Keras supports for F-beta over multi-class outputs.","triggerScenarios":"keras.metrics.FBetaScore(average='samples'); 'micro ' with trailing whitespace; the string 'None' instead of None; sklearn-style 'binary'.","commonSituations":"Porting sklearn f1_score parameter names to Keras; config typos; assuming a binary mode exists (use 2D one-hot output instead).","solutions":["Use exactly None, 'micro', 'macro', or 'weighted'.","For binary problems use keras.metrics.F1Score on (batch, 1) output or Precision/Recall.","Strip/normalize config strings before passing them."],"exampleFix":"# before\nm = keras.metrics.FBetaScore(beta=1.0, average='binary')\n\n# after\nm = keras.metrics.FBetaScore(beta=1.0, average='macro')","handlingStrategy":"validation","validationCode":"assert average in (None, 'micro', 'macro', 'weighted'), average","typeGuard":"def is_valid_average(v) -> bool:\n    return v in (None, 'micro', 'macro', 'weighted')","tryCatchPattern":null,"preventionTips":["Don't assume sklearn parameter names transfer.","Centralize metric construction behind one validated config schema."],"tags":["keras","metrics","fbeta","argument-validation"],"backgroundTag":"invalid-enum-value","analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}