keras-team/keras · error · ValueError
Invalid `beta` argument value. It should be a Python float.
Error message
Invalid `beta` argument value. It should be a Python float. Received: beta={beta} of type '{type(beta)}' What it means
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.
Source
Thrown at keras/src/metrics/f_score_metrics.py:86
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}"
)
if threshold is not None:
if not isinstance(threshold, float):
raise ValueError(
"Invalid `threshold` argument value. "
"It should be a Python float. "
f"Received: threshold={threshold} "
f"of type '{type(threshold)}'"View on GitHub (pinned to 7a34a03db6)
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.
Example fix
# before m = keras.metrics.FBetaScore(beta=1, average='macro') # after m = keras.metrics.FBetaScore(beta=1.0, average='macro') # or simply m = keras.metrics.F1Score(average='macro')
Defensive patterns
Strategy: type-guard
Validate before calling
beta = float(beta)
Type guard
def is_float_beta(v) -> bool:
return isinstance(v, float) Prevention
- Always write beta with a decimal point (1.0, 2.0).
- Coerce numeric config values with float() at load.
When it happens
Trigger: keras.metrics.FBetaScore(beta=1) (int, not 1.0); beta parsed from JSON/YAML as int; numpy floats or tf.Variable.
Common situations: Writing beta=1 or beta=2 as integers (the classic F1 case); config files storing 2 instead of 2.0.
Related errors
- Invalid `threshold` argument value. It should be a Python fl
- Invalid `average` argument value. Expected one of: {None, 'm
- Invalid `beta` argument value. It should be > 0. Received: b
- Invalid `threshold` argument value. It should verify 0 < thr
- FBetaScore expects 2D inputs with shape (batch_size, output_
AI-assisted analysis of keras-team/keras@7a34a03db6 (2026-08-25).
Data as JSON: /api/errors/8843612fb1874ba9.
Report an issue: GitHub.