[MRG+1] remove n_nonzero_coefs from attr of LassoLarsCV + clean up call hierarchy#9004
Conversation
| least_squares) | ||
|
|
||
| g1 = arrayfuncs.min_pos((C - Cov) / (AA - corr_eq_dir + tiny)) | ||
| g1 = arrayfuncs.min_pos((C - Cov) / (AA - corr_eq_dir + tiny32)) |
There was a problem hiding this comment.
tiny was not enough for #8475
and I think that 1.1754944e-38 is small enough (rather than 2.2250738585072014e-308)
| alpha = 0. # n_nonzero_coefs parametrization takes priority | ||
| max_iter = self.n_nonzero_coefs | ||
| else: | ||
| max_iter = self.max_iter |
There was a problem hiding this comment.
this has been moved to Lars.fit to avoid the magic of hacking instance attributes
sklearn/linear_model/least_angle.py
Outdated
| # it will call a lasso internally when self if LassoLarsCV | ||
| # as self.method == 'lasso' | ||
| Lars.fit(self, X, y) | ||
| Lars._fit(self, X, y, max_iter=self.max_iter, alpha=best_alpha, |
There was a problem hiding this comment.
now self.max_iter is not ignored
There was a problem hiding this comment.
Is it the case that previously the call to Lars.fit reverted to a call to lasso_lars with alpha_min=0, while now alpha_min=best_alpha?
There was a problem hiding this comment.
great! so we save a bit of computation that we didn't need to do previously.
There was a problem hiding this comment.
Should we maybe just say self._fit now?
sklearn/linear_model/least_angle.py
Outdated
| # XXX deprecate? | ||
| @property | ||
| @deprecated("Attribute alpha is deprecated in 0.18 and " | ||
| "will be removed in 0.20. See 'alpha_' instead") |
There was a problem hiding this comment.
this was a hack to be able to call Lars.fit but the CV classes should have an alpha_ but no alpha param
| lars_cv.fit(X, y) | ||
| np.testing.assert_array_less(old_alpha, lars_cv.alpha_) | ||
| old_alpha = lars_cv.alpha_ | ||
| assert_false(hasattr(lars_cv, 'n_nonzero_coefs')) |
There was a problem hiding this comment.
maybe a test for the ignored max_iter?
| sys.stdout.flush() | ||
|
|
||
| tiny = np.finfo(np.float).tiny # to avoid division by 0 warning | ||
| tiny32 = np.finfo(np.float32).tiny # to avoid division by 0 warning |
There was a problem hiding this comment.
for the record tiny32 was introduced here 294d4b6
Codecov Report
@@ Coverage Diff @@
## master #9004 +/- ##
==========================================
+ Coverage 95.91% 95.92% +<.01%
==========================================
Files 331 331
Lines 59851 59960 +109
==========================================
+ Hits 57409 57516 +107
- Misses 2442 2444 +2
Continue to review full report at Codecov.
|
ea66a5b to
fde74da
Compare
|
good to go on my end appveyor error is an appveyor outage so is unrelated |
sklearn/linear_model/least_angle.py
Outdated
| """ | ||
| X, y = check_X_y(X, y, y_numeric=True, multi_output=True) | ||
| def _fit(self, X, y, max_iter, alpha, fit_path, Xy=None): | ||
| """Aux method to fit the model using X, y as training data""" |
There was a problem hiding this comment.
I know it's private, but I think it should still say "Auxiliary" :P
|
Other than the two extremely minor comments this LGTM. The regression test indeed fails on master and passes here. Clear improvement in terms of the code. |
002c95a to
70338a0
Compare
| self.copy_X = copy_X | ||
| self.positive = positive | ||
| # XXX : we don't use super(LarsCV, self).__init__ | ||
| # to avoid setting n_nonzero_coefs |
There was a problem hiding this comment.
Technically it tells us that we have the wrong inheritance diagram. But... I don't bother.
|
LGTM. Merging |
…ll hierarchy (scikit-learn#9004) * FIX : remove n_nonzero_coefs from attr of LassoLarsCV + clean up call to Lars._fit * cleanup * fix deprecation warning + clarify warning * add test * pep8 * adddress comments
…ll hierarchy (scikit-learn#9004) * FIX : remove n_nonzero_coefs from attr of LassoLarsCV + clean up call to Lars._fit * cleanup * fix deprecation warning + clarify warning * add test * pep8 * adddress comments
…ll hierarchy (scikit-learn#9004) * FIX : remove n_nonzero_coefs from attr of LassoLarsCV + clean up call to Lars._fit * cleanup * fix deprecation warning + clarify warning * add test * pep8 * adddress comments
…ll hierarchy (scikit-learn#9004) * FIX : remove n_nonzero_coefs from attr of LassoLarsCV + clean up call to Lars._fit * cleanup * fix deprecation warning + clarify warning * add test * pep8 * adddress comments
…ll hierarchy (scikit-learn#9004) * FIX : remove n_nonzero_coefs from attr of LassoLarsCV + clean up call to Lars._fit * cleanup * fix deprecation warning + clarify warning * add test * pep8 * adddress comments
…ll hierarchy (scikit-learn#9004) * FIX : remove n_nonzero_coefs from attr of LassoLarsCV + clean up call to Lars._fit * cleanup * fix deprecation warning + clarify warning * add test * pep8 * adddress comments
…ll hierarchy (scikit-learn#9004) * FIX : remove n_nonzero_coefs from attr of LassoLarsCV + clean up call to Lars._fit * cleanup * fix deprecation warning + clarify warning * add test * pep8 * adddress comments
…ll hierarchy (scikit-learn#9004) * FIX : remove n_nonzero_coefs from attr of LassoLarsCV + clean up call to Lars._fit * cleanup * fix deprecation warning + clarify warning * add test * pep8 * adddress comments
Reference Issue
Fixes #8475
What does this implement/fix? Explain your changes.
introduce a private _fit method in Lars to fit with explicit params without
having to hack the instance attributes.
It also fixes a call to Lars.fit that was ignoring the max_iter parameter.
Any other comments?
Nope