Skip to content

[MRG+2] ENH: used SelectorMixin in BaseRandomizedLinearModel #8263

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 13, 2017

Conversation

dalmia
Copy link
Contributor

@dalmia dalmia commented Feb 1, 2017

Reference Issue

Fixes #8259

What does this implement/fix? Explain your changes.

This uses SelectorMixin in BaseRandomizedLinearModel renaming the get_support function to _get_support_mask in order to utilize the transform() and inverse_transform() methods provided by SelectorMixin.

@jnothman
Copy link
Member

jnothman commented Feb 1, 2017

get_support() is public and cannot just be removed from one release to the next. Please keep it.

@@ -128,6 +128,9 @@ def _get_support_mask(self, indices=False):
mask = self.scores_ > self.selection_threshold
return mask if not indices else np.where(mask)[0]

def get_support(self, indices=False):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

docstring, please

@jnothman
Copy link
Member

jnothman commented Feb 7, 2017

LGTM. I note that this also fixes a bug where Randomized* breaks with sparse input.

@jnothman jnothman changed the title [MRG] ENH: used SelectorMixin in BaseRandomizedLinearModel [MRG+1] ENH: used SelectorMixin in BaseRandomizedLinearModel Feb 7, 2017
@jnothman jnothman added the Bug label Feb 7, 2017
@dalmia
Copy link
Contributor Author

dalmia commented Feb 7, 2017

So does this need an extra review or is it okay for merge?

@jnothman
Copy link
Member

jnothman commented Feb 7, 2017 via email

@dalmia
Copy link
Contributor Author

dalmia commented Feb 7, 2017

Thanks for clearing it up. Just intended to know if there is some other improvement under consideration.

@tguillemot
Copy link
Contributor

LGTM
Thanks @dalmia

Copy link
Member

@TomDLT TomDLT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Can you add a bug fix entry in doc/whats_new.rst?

@TomDLT TomDLT changed the title [MRG+1] ENH: used SelectorMixin in BaseRandomizedLinearModel [MRG+2] ENH: used SelectorMixin in BaseRandomizedLinearModel Feb 10, 2017
@dalmia
Copy link
Contributor Author

dalmia commented Feb 10, 2017

@TomDLT 👍

Xt = np.zeros((X.shape[0], support.size))
Xt[:, support] = X
return Xt
def get_support(self, indices=False):
Copy link
Member

@lesteve lesteve Feb 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am confused why do you need to override SelectorMixin.get_support? Should _get_support_mask not be:

def _get_support_mask(self):
    check_is_fitted(self, 'scores_')
    return self.scores_ > self.selection_threshold

and then SelectorMixin.get_support would take over and do what it is supposed to do?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, it is better

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with a docstring

        """
        Get the boolean mask indicating which features are selected

        Returns
        -------
        support : boolean array of shape [# input features]
            An element is True iff its corresponding feature is selected for
            retention.
        """

Copy link
Contributor Author

@dalmia dalmia Feb 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was specified to me earlier by @jnothman that since get_support was already public, we shouldn't remove it from one release to the next.

Copy link
Member

@TomDLT TomDLT Feb 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess he overlooked it:
As the class now inherits from SelectorMixin, the method get_support is inherited so it is not removed.

Copy link
Member

@TomDLT TomDLT Feb 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just realized that as you removed TransformerMixin, the class does not inherit anymore from the method fit_transform, which is public and should not be removed.
Why don't you keep TransformerMixin ?

Copy link
Contributor Author

@dalmia dalmia Feb 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I removed it since it seemed like SelectorMixin inherits TransformerMixin?

class SelectorMixin(six.with_metaclass(ABCMeta, TransformerMixin)):

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh yes of course, my mistake

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please address the comment on get_support

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I'll make the change.

@codecov
Copy link

codecov bot commented Feb 10, 2017

Codecov Report

❗ No coverage uploaded for pull request base (master@dfcf632). Click here to learn what that means.

@@            Coverage Diff            @@
##             master    #8263   +/-   ##
=========================================
  Coverage          ?   94.74%           
=========================================
  Files             ?      342           
  Lines             ?    60722           
  Branches          ?        0           
=========================================
  Hits              ?    57531           
  Misses            ?     3191           
  Partials          ?        0
Impacted Files Coverage Δ
sklearn/linear_model/randomized_l1.py 94.7% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update dfcf632...873a8e7. Read the comment docs.

@TomDLT TomDLT merged commit 38d59c7 into scikit-learn:master Feb 13, 2017
@dalmia dalmia deleted the 8259 branch February 13, 2017 14:20
sergeyf pushed a commit to sergeyf/scikit-learn that referenced this pull request Feb 28, 2017
…learn#8263)

* ENH: used SelectorMixin in BaseRandomizedLinearModel

* FIX: added get_support to return _get_support_mask

* FIX: added docstring for get_support()

* DOC: added bug fix entry to whats_new

* FIX: removed redundant get_support()
@Przemo10 Przemo10 mentioned this pull request Mar 17, 2017
Sundrique pushed a commit to Sundrique/scikit-learn that referenced this pull request Jun 14, 2017
…learn#8263)

* ENH: used SelectorMixin in BaseRandomizedLinearModel

* FIX: added get_support to return _get_support_mask

* FIX: added docstring for get_support()

* DOC: added bug fix entry to whats_new

* FIX: removed redundant get_support()
NelleV pushed a commit to NelleV/scikit-learn that referenced this pull request Aug 11, 2017
…learn#8263)

* ENH: used SelectorMixin in BaseRandomizedLinearModel

* FIX: added get_support to return _get_support_mask

* FIX: added docstring for get_support()

* DOC: added bug fix entry to whats_new

* FIX: removed redundant get_support()
paulha pushed a commit to paulha/scikit-learn that referenced this pull request Aug 19, 2017
…learn#8263)

* ENH: used SelectorMixin in BaseRandomizedLinearModel

* FIX: added get_support to return _get_support_mask

* FIX: added docstring for get_support()

* DOC: added bug fix entry to whats_new

* FIX: removed redundant get_support()
maskani-moh pushed a commit to maskani-moh/scikit-learn that referenced this pull request Nov 15, 2017
…learn#8263)

* ENH: used SelectorMixin in BaseRandomizedLinearModel

* FIX: added get_support to return _get_support_mask

* FIX: added docstring for get_support()

* DOC: added bug fix entry to whats_new

* FIX: removed redundant get_support()
lemonlaug pushed a commit to lemonlaug/scikit-learn that referenced this pull request Jan 6, 2021
…learn#8263)

* ENH: used SelectorMixin in BaseRandomizedLinearModel

* FIX: added get_support to return _get_support_mask

* FIX: added docstring for get_support()

* DOC: added bug fix entry to whats_new

* FIX: removed redundant get_support()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use SelectorMixin in BaseRandomizedLinearModel
5 participants