Skip to content

Commit

Permalink
Merge pull request #2921 from ericpre/fix_multifit_ridge_regression
Browse files Browse the repository at this point in the history
Fix passing keyword argument to ridge_regression
  • Loading branch information
jlaehne committed Apr 8, 2022
2 parents 6db1f80 + 448185e commit 625d566
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
5 changes: 4 additions & 1 deletion hyperspy/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1965,7 +1965,10 @@ def multifit(
# 3. leave earlier because we don't need to go iterate over
# the navigation indices
kwargs['only_current'] = False
kwargs['show_progressbar'] = show_progressbar
# Add the 'show_progressbar' only with lazy signal to avoid
# passing it down to 'ridge_regression'
if self.signal._lazy:
kwargs['show_progressbar'] = show_progressbar
self.fit( **kwargs)

# TODO: check what happen to linear twinned parameter
Expand Down
14 changes: 14 additions & 0 deletions hyperspy/tests/model/test_linear_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,20 @@ def test_channel_switches(self, weighted):
single_nonlinear = m.as_signal()
np.testing.assert_allclose(single(), single_nonlinear())

def test_multifit_ridge(self, weighted):
pytest.importorskip("sklearn")
m = self.m
L = Gaussian(centre=15.)
L.set_parameters_not_free(['centre', 'sigma'])
m.append(L)

if m.signal._lazy:
with pytest.raises(ValueError):
m.multifit(optimizer='ridge_regression')
return
else:
m.multifit(optimizer='ridge_regression')


class TestLinearFitting:

Expand Down

0 comments on commit 625d566

Please sign in to comment.