pyGAM icon indicating copy to clipboard operation
pyGAM copied to clipboard

Fix #545: Resolve empty Effective DoF in summary() for overparameterized models

Open hritikkumarpradhan opened this issue 8 months ago • 0 comments

Fixes #545

Description

This PR fixes the bug where the Effective Degrees of Freedom (EDoF) per term in summary() is printed as an empty string for overparameterized models (where the number of samples is less than the number of coefficients).

Changes Made

  1. Modify summary() in pygam.py to correctly fall back to float("nan") instead of "" for overparameterized models so the summary table is properly formatted.
    1. Add a warnings.warn specifically calling out that the model is overparameterized and the EDoF per term cannot be reliably computed.
    1. Optimization/Vectorization: Replaced np.diagonal(U1.dot(U1.T)) with (U1**2).sum(axis=1) to avoid calculating a full dense matrix just to slice the diagonal, improving efficiency while maintaining identical results.
    1. Updated test assertions in tests/test_GAM_methods.py to capture this warning properly. All existing tests pass correctly.

hritikkumarpradhan avatar Mar 20 '26 09:03 hritikkumarpradhan