-
-
Notifications
You must be signed in to change notification settings - Fork 26k
[MRG+1] compute poly features directly #3239
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
Conversation
Unfortunately the travis failure highlights that |
Wouldn't it be interesting to add an option in the public API to let the user choose between the 2 (only interaction terms or all degree 2 terms)? |
Tests pass, except the known OMP failure on 2.6. Added a second commit for interaction features only. |
Thanks! +1 for merge. |
I forgot to ask, have you quickly benchmarked the empirical runtime complexity of this method vs master? |
Current master: >>> %timeit PolynomialFeatures._power_matrix(3, 2, False)
1000 loops, best of 3: 244 us per loop
>>> %timeit PolynomialFeatures._power_matrix(10, 3, False)
1 loops, best of 3: 847 ms per loop
>>> PolynomialFeatures._power_matrix(30, 2, False)
# Ctrl+C after waiting 1m30 This PR: >>> %timeit PolynomialFeatures._power_matrix(3, 2, False, False)
1000 loops, best of 3: 337 us per loop
>>> %timeit PolynomialFeatures._power_matrix(10, 3, False, False)
100 loops, best of 3: 9.73 ms per loop
>>> %timeit PolynomialFeatures._power_matrix(30, 2, False, False)
100 loops, best of 3: 17.1 ms per loop |
Thanks! |
Neat! I'm not sure about the clarity of |
return powers[i] | ||
comb = (combinations if interaction_only else combinations_w_r) | ||
combn = chain(*(comb(range(n_features), i) | ||
for i in range(not include_bias, degree + 1))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can use chain.from_iterable
to avoid to use a *
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point.
compute poly features directly and allow interaction features only
@hamsal reports an issue that appears to result from this merge at On 6 June 2014 02:03, Lars Buitinck [email protected] wrote:
|
Here's a much simpler alternative to #3194 for fixing #3191.
itertools
and NumPy have all the required functionality.The great thing about this approach is that we can turn the actual polynomials (x², y²) off and get only the interaction terms (xy) by substituting
combinations
forcombinations_with_replacement
.