stanza.analysis.criterion

Fit quality assessment criteria for curve fitting.

This module provides functions to evaluate the quality of nonlinear curve fits using statistically robust metrics like R² and NRMSE.

Module Contents

Functions

NameDescription
fit_quality_criterionEvaluate fit quality using R² and NRMSE metrics.

API

1stanza.analysis.criterion.fit_quality_criterion(
2 x_data: numpy.ndarray,
3 y_data: numpy.ndarray,
4 y_pred: numpy.ndarray,
5 r_squared_threshold: float = 0.7,
6 nrmse_threshold: float = 0.2
7) -> bool

Evaluate fit quality using R² and NRMSE metrics.

This criterion evaluates both how well the model explains variance (R²) and how small the errors are relative to the data range (NRMSE).

Parameters:

x_data
numpy.ndarray

Input x values (used for context, not in calculation)

y_data
numpy.ndarray

Observed y values

y_pred
numpy.ndarray

Predicted y values from the fitted model

r_squared_threshold
floatDefaults to 0.7

Minimum R² value for acceptable fit. Default 0.7

nrmse_threshold
floatDefaults to 0.2

Maximum NRMSE (normalized RMSE) for acceptable fit.

Returns:

True if fit quality is GOOD (passes both criteria), False if POOR Notes:

  • R² (coefficient of determination) measures the proportion of variance in the data explained by the model. Range: [0, 1], higher is better.
  • NRMSE (normalized root mean square error) measures prediction error relative to data range. Range: [0, ∞), lower is better.
  • These metrics are appropriate for nonlinear models, unlike reduced chi-squared which requires known degrees of freedom.