[MRG+1] Fix precomputation of Gram matrix in Lars #5359

Merged
merged 1 commit into from Jun 13, 2017

Conversation

Projects
None yet
4 participants
@TomDLT
Member

TomDLT commented Oct 7, 2015

This is a fix for the bug reported in #1856.
The parameter precompute (in RandomizedLasso, Lars, LarsLasso, LarsCV and LarsLassoCV) were not consistent and some values proposed in the docstrings (False, array) could raise errors.

This PR includes the following steps:

  • improve lars_path, to allow Gram=True and Gram=False.
  • change the _get_gram method, to handle precompute in the same way in every class.
  • add a warning when an array is given in precompute, in LarsCV and LarsLassoCV.
  • update the docstring.
  • add some tests. test_randomized_l1.py is also updated to be shorter (from 1.582s to 0.817s). test_least_angle.py goes from 1.305s to 1.465s.
+ # As we use cross-validation, the Gram matrix is not precomputed here
+ Gram = self.precompute
+ if hasattr(Gram, '__array__'):
+ warnings.warn("Parameter 'precompute' cannot be an array in "

This comment has been minimized.

@arthurmensch

arthurmensch Oct 7, 2015

Contributor

I would say raise an error instead of a warning but it depends on how much we want to nurse the user.

@arthurmensch

arthurmensch Oct 7, 2015

Contributor

I would say raise an error instead of a warning but it depends on how much we want to nurse the user.

This comment has been minimized.

@TomDLT

TomDLT Oct 7, 2015

Member

I was thinking about avoiding an error when a user changes Lars(precompute=G).fit(X, y) into LarsCV(precompute=G).fit(X, y). But it is kind of nursing.

@TomDLT

TomDLT Oct 7, 2015

Member

I was thinking about avoiding an error when a user changes Lars(precompute=G).fit(X, y) into LarsCV(precompute=G).fit(X, y). But it is kind of nursing.

+ precompute=precompute, n_resampling=n_resampling)
+ feature_scores_2 = clf.fit(X, y).scores_
+ assert_array_equal(feature_scores_1, feature_scores_2)
+

This comment has been minimized.

@arthurmensch

arthurmensch Oct 7, 2015

Contributor

Do we need test for precompute = array_like ?

@arthurmensch

arthurmensch Oct 7, 2015

Contributor

Do we need test for precompute = array_like ?

This comment has been minimized.

@TomDLT

TomDLT Oct 7, 2015

Member

In Randomized lasso, precompute = array_like is used only for the computation of alpha when alpha='aic' or 'bic'.
But I can definitely test it. (Done)

@TomDLT

TomDLT Oct 7, 2015

Member

In Randomized lasso, precompute = array_like is used only for the computation of alpha when alpha='aic' or 'bic'.
But I can definitely test it. (Done)

@TomDLT TomDLT added this to the 0.17 milestone Oct 7, 2015

@TomDLT TomDLT changed the title from [WIP] Fix precomputation of Gram matrix in Lars to [MRG] Fix precomputation of Gram matrix in Lars Oct 7, 2015

@TomDLT TomDLT removed this from the 0.17 milestone Dec 5, 2015

@agramfort

This comment has been minimized.

Show comment
Hide comment
@agramfort

agramfort Jun 6, 2017

Member

LGTM

@TomDLT can you update what's new to document the bug fix?

Member

agramfort commented Jun 6, 2017

LGTM

@TomDLT can you update what's new to document the bug fix?

@TomDLT

This comment has been minimized.

Show comment
Hide comment
@TomDLT

TomDLT Jun 6, 2017

Member

done

Member

TomDLT commented Jun 6, 2017

done

@agramfort

This comment has been minimized.

Show comment
Hide comment
@agramfort

agramfort Jun 6, 2017

Member

+1 for MRG when CIs are happy

thx @TomDLT

Member

agramfort commented Jun 6, 2017

+1 for MRG when CIs are happy

thx @TomDLT

@arthurmensch

To me it would make more sense to explicitely feed the gram matrix in the .fit but I reckon this has little usage anyway. LGTM

- return Gram
+ def _get_gram(self, precompute, X, y):
+ if (not hasattr(precompute, '__array__')) and (
+ (precompute is True) or

This comment has been minimized.

@arthurmensch

arthurmensch Jun 6, 2017

Contributor

Can be simplified ?

@arthurmensch

arthurmensch Jun 6, 2017

Contributor

Can be simplified ?

@agramfort agramfort changed the title from [MRG] Fix precomputation of Gram matrix in Lars to [MRG+1] Fix precomputation of Gram matrix in Lars Jun 7, 2017

@agramfort

This comment has been minimized.

Show comment
Hide comment
@agramfort

agramfort Jun 7, 2017

Member

CIs are happy here

Member

agramfort commented Jun 7, 2017

CIs are happy here

@agramfort

This comment has been minimized.

Show comment
Hide comment
@agramfort

agramfort Jun 7, 2017

Member

@TomDLT you need to rebase

Member

agramfort commented Jun 7, 2017

@TomDLT you need to rebase

@TomDLT

This comment has been minimized.

Show comment
Hide comment
@TomDLT

TomDLT Jun 9, 2017

Member

All checks have passed

Member

TomDLT commented Jun 9, 2017

All checks have passed

@agramfort

This comment has been minimized.

Show comment
Hide comment
@agramfort

agramfort Jun 10, 2017

Member

@TomDLT please fix conflicts here and then let's merge.

Member

agramfort commented Jun 10, 2017

@TomDLT please fix conflicts here and then let's merge.

@TomDLT

This comment has been minimized.

Show comment
Hide comment
@TomDLT

TomDLT Jun 13, 2017

Member

The AppVeyor failures are on master #9111

Member

TomDLT commented Jun 13, 2017

The AppVeyor failures are on master #9111

@agramfort agramfort merged commit bb1299b into scikit-learn:master Jun 13, 2017

2 of 3 checks passed

continuous-integration/appveyor/pr AppVeyor build failed
Details
ci/circleci Your tests passed on CircleCI!
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@agramfort

This comment has been minimized.

Show comment
Hide comment
Member

agramfort commented Jun 13, 2017

thanks @TomDLT

Sundrique added a commit to Sundrique/scikit-learn that referenced this pull request Jun 14, 2017

dmohns added a commit to dmohns/scikit-learn that referenced this pull request Aug 7, 2017

dmohns added a commit to dmohns/scikit-learn that referenced this pull request Aug 7, 2017

NelleV added a commit to NelleV/scikit-learn that referenced this pull request Aug 11, 2017

paulha added a commit to paulha/scikit-learn that referenced this pull request Aug 19, 2017

AishwaryaRK added a commit to AishwaryaRK/scikit-learn that referenced this pull request Aug 29, 2017

maskani-moh added a commit to maskani-moh/scikit-learn that referenced this pull request Nov 15, 2017

jwjohnson314 pushed a commit to jwjohnson314/scikit-learn that referenced this pull request Dec 18, 2017

@TomDLT TomDLT deleted the TomDLT:lars branch Jun 15, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment