pyGAM
pyGAM copied to clipboard
Fix empty Effective DoF in summary() for overparametrized models #535
Resolve Empty Effective DoF in summary() for overparametrized models
When a pyGAM model is overparameterized (number of samples < number of coefficients), the summary() method previously displayed an empty string for the term-by-term Effective Degrees of Freedom (EDoF). This was due to the statistics computation relying on a truncated SVD result (U1) whose size was limited by the number of samples.
Changes:
- Refined EDoF Calculation: Updated
_estimate_model_statistics()to use the robust formula $diag(B \cdot WB)$ for computingedof_per_coef. This formula correctly handles cases where $n < m$ and ensures the EDoF array always matches the number of coefficients. -
- Summary Method Update: Updated the
summary()method to rely on the now-correctly-sized EDoF values.
- Summary Method Update: Updated the
-
- Transparent Warning: Added a warning to the
summary()output to inform users when overparameterization is detected, clarifying that while EDoF values are now displayed, they should be interpreted with caution in these settings.
- Transparent Warning: Added a warning to the
-
- Test Coverage: Updated
test_more_splines_than_samplesinpygam/tests/test_GAM_methods.pyto assert the correct EDoF length. This fix ensures that users can always inspect how their subterms consume degrees of freedom, even when working with small datasets or complex spline settings.
- Test Coverage: Updated