Skip to content
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

transform_feature_names for scalers #229

Merged
merged 5 commits into from
Aug 1, 2017
Merged

Conversation

kmike
Copy link
Contributor

@kmike kmike commented Jul 31, 2017

I can see 3 main ways to show feature names for scalers:

  1. display feature names as-is (like it is done in [MRG] ENH Add get_feature_names for various transformers scikit-learn/scikit-learn#6431);
  2. show that feature names are scaled/normalized, but hide the details, e.g. scaled(x1);
  3. show the complete formula, e.g. (x1*0.312 - 1.232) for StandardScaler

In this PR (1) is implemented; at least it is more useful than doing nothing.

It seems we may want an optional "verbose mode" for feature names, as there are use cases you want the whole formula, and there are use cases you only care about input feature names.

@codecov-io
Copy link

codecov-io commented Jul 31, 2017

Codecov Report

Merging #229 into master will increase coverage by <.01%.
The diff coverage is 100%.

@@            Coverage Diff             @@
##           master     #229      +/-   ##
==========================================
+ Coverage   97.26%   97.27%   +<.01%     
==========================================
  Files          42       42              
  Lines        2673     2682       +9     
  Branches      515      517       +2     
==========================================
+ Hits         2600     2609       +9     
  Misses         38       38              
  Partials       35       35
Impacted Files Coverage Δ
eli5/sklearn/transform.py 100% <100%> (ø) ⬆️

@kmike kmike force-pushed the transform_feature_names_scalers branch from 10bfa51 to a0fa0d8 Compare July 31, 2017 15:27
@kmike
Copy link
Contributor Author

kmike commented Jul 31, 2017

@lopuhin @jnothman what do you think?

Copy link
Contributor

@lopuhin lopuhin left a comment

Choose a reason for hiding this comment

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

Looks good to me, this is the behaviour I would expect. Left a minor question.

if in_names is None:
in_names = _get_feature_names(est, feature_names=in_names,
num_features=est.scale_.shape[0])
return [name for name in in_names]
Copy link
Contributor

Choose a reason for hiding this comment

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

what does this list comprehension do - is it the same as list(in_names), or you wanted to add something more?

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'm converting FeatureNames instance (which comes from _get_feature_names) to a list. It is also a left-over from my experiments with more elaborate feature names, when you don't pass names as-is.

Copy link
Contributor

@jnothman jnothman left a comment

Choose a reason for hiding this comment

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

I think this is right, though as I've suggested elsewhere, for TFIDF I'd like the IDF to be noted. I've also wished we could just avoid this decision by having a structured representation of feature description. Something JSONable, for instance.

The tests are changed in #208, and while I dither over fixing up that PR, I wonder if we should pull the test changes into something separate.

@transform_feature_names.register(StandardScaler)
@transform_feature_names.register(MaxAbsScaler)
@transform_feature_names.register(RobustScaler)
def _select_scaling(est, in_names=None):
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you mean transform, not select

@jnothman
Copy link
Contributor

jnothman commented Aug 1, 2017

Outputting feature descriptions as JsonLogic, perhaps??

@kmike kmike merged commit ae0249e into master Aug 1, 2017
@kmike
Copy link
Contributor Author

kmike commented Aug 1, 2017

I like the JsonLogic idea, to output expressions used for computing feature names.

+1 to pull in test changes to make updating #208 easier, but I'm also fine with merging #208 with a few minor changes :)

@kmike kmike deleted the transform_feature_names_scalers branch August 1, 2017 18:22
@jnothman
Copy link
Contributor

jnothman commented Aug 1, 2017 via email

@jnothman
Copy link
Contributor

jnothman commented Aug 1, 2017 via email

@kmike
Copy link
Contributor Author

kmike commented Aug 2, 2017

We would still provide html/text/dataframe/(simplified json?) exports if we use jsonlogic internally, so data scientists should be fine :)

@kmike kmike added this to the 0.8 milestone Aug 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants