You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
BUG: GLS fit_regularized, different params if sigma is 1-dim or diag 2 dim #7755
I don't see the problem right now. Needs investigating.
Fixing a unit test for GLS.fit_regularized that used incorrect kwarg "weights" #7751
I think the results, specifically params, should be the same if sigma = 1/ wghts and sigma = np.diag(1 / wgths)
The second matches the params from the WLS(... weights=wgths) estimate.
The former looks like an unpenalized estimate
my current version form test_regression
the last two asserts fail if I use `model_gls = GLS(yvec, xmat, sigma=1 / wgt)
def test_regularized_predict():
n = 100
p = 5
np.random.seed(3132)
xmat = np.random.normal(size=(n, p))
yvec = xmat.sum(1) + np.random.normal(size=n)
wgt = np.random.uniform(1, 2, n)
model_wls = WLS(yvec, xmat, weights=wgt)
# TODO: params is not the same in GLS if sigma=1 / wgth, i.e 1-dim
model_gls = GLS(yvec, xmat, sigma=np.diag(1 / wgt))
res = []
for model1 in [model_wls, model_gls]:
result1 = model1.fit_regularized(alpha=20.0, L1_wt=0.5, refit=True)
res.append(result1)
params = result1.params
fittedvalues = np.dot(xmat, params)
pr = model1.predict(result1.params)
assert_allclose(fittedvalues, pr)
assert_allclose(result1.fittedvalues, pr)
pr = result1.predict()
assert_allclose(fittedvalues, pr)
assert_allclose(res[0].model.wendog, res[1].model.wendog, rtol=1e-10)
assert_allclose(res[0].model.wexog, res[1].model.wexog, rtol=1e-10)
assert_allclose(res[0].fittedvalues, res[1].fittedvalues, rtol=1e-10)
assert_allclose(res[0].params, res[1].params, rtol=1e-10)
Activity
josef-pkt commentedon Sep 25, 2021
found it
in GLS.fit_regularized
If sigma is 1-dim, then
np.diag(self.sigma)creates diagonal matrix, and zero division.The
np.sum(1 / np.diag(self.sigma))and alpha are infjosef-pkt commentedon Sep 25, 2021
fix is
BUG: GLS fit_regularized: fix if signa is 1-dim closes statsmodels#7755