keras-team/keras · error · ValueError

Invalid `average` argument value. Expected one of: {None, 'm

Error message

Invalid `average` argument value. Expected one of: {None, 'micro', 'macro', 'weighted'}. Received: average={average}

What it means

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.

Source

Thrown at keras/src/metrics/f_score_metrics.py:79

    >>> result = metric.result()
    >>> result
    [0.3846154 , 0.90909094, 0.8333334 ]
    """

    def __init__(
        self,
        average=None,
        beta=1.0,
        threshold=None,
        name="fbeta_score",
        dtype=None,
    ):
        super().__init__(name=name, dtype=dtype)
        # Metric should be maximized during optimization.
        self._direction = "up"

        if average not in (None, "micro", "macro", "weighted"):
            raise ValueError(
                "Invalid `average` argument value. Expected one of: "
                "{None, 'micro', 'macro', 'weighted'}. "
                f"Received: average={average}"
            )

        if not isinstance(beta, float):
            raise ValueError(
                "Invalid `beta` argument value. "
                "It should be a Python float. "
                f"Received: beta={beta} of type '{type(beta)}'"
            )
        if beta <= 0.0:
            raise ValueError(
                "Invalid `beta` argument value. "
                "It should be > 0. "
                f"Received: beta={beta}"
            )

View on GitHub (pinned to 7a34a03db6)

Solutions

  1. Use exactly None, 'micro', 'macro', or 'weighted'.
  2. For binary problems use keras.metrics.F1Score on (batch, 1) output or Precision/Recall.
  3. Strip/normalize config strings before passing them.

Example fix

# before
m = keras.metrics.FBetaScore(beta=1.0, average='binary')

# after
m = keras.metrics.FBetaScore(beta=1.0, average='macro')
Defensive patterns

Strategy: validation

Validate before calling

assert average in (None, 'micro', 'macro', 'weighted'), average

Type guard

def is_valid_average(v) -> bool:
    return v in (None, 'micro', 'macro', 'weighted')

Prevention

When it happens

Trigger: keras.metrics.FBetaScore(average='samples'); 'micro ' with trailing whitespace; the string 'None' instead of None; sklearn-style 'binary'.

Common situations: Porting sklearn f1_score parameter names to Keras; config typos; assuming a binary mode exists (use 2D one-hot output instead).

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of keras-team/keras@7a34a03db6 (2026-08-25). Data as JSON: /api/errors/b39ea6f2c8a6bdb4. Report an issue: GitHub.