Repository navigation
ENH add minimal degree support to PolynomialFeatures - #20250
Conversation
|
Could you please run a quick benchmark to check that this does not introduce any significant performance regression when |
|
Can you please extend the tests to check the output of |
ogrisel
left a comment
There was a problem hiding this comment.
LGTM. I did not check the code itself in details but since the tests look comprehensive enough, I trust this PR to be correct :)
Also you did not run the requested quick non-regression benchmark I requested in #20250 (comment) as far as I can see.
Just a few more tests improvement suggestions (I could not resist):
That's right. I did not yet pop up on top of my priority list (and there is not really a code change from which I expect a slow down. Unfortunately, the git diff is blurred by the additional indentation.). |
|
Take away: |
rth
left a comment
There was a problem hiding this comment.
Thanks @lorentzenchr ! This would be quite useful indeed!
Generally LGTM. Note that there is still one comment to address in https://github.com/scikit-learn/scikit-learn/pull/20250/files#r651049827 from Olivier's review.
| new_index.append(current_col) | ||
| index = new_index | ||
|
|
||
| Xout[:, :] = XP[:, n_XP - n_Xout :] |
There was a problem hiding this comment.
There is probably no need to pre-allocate Xout in this case,
| Xout[:, :] = XP[:, n_XP - n_Xout :] | |
| Xout = XP[:, n_XP - n_Xout :].copy() |
So it's complicated to compute only the columns we need in the above loop directly?
There was a problem hiding this comment.
Now, the allocation with np.empty is only in if self.include_bias:.
So it's complicated to compute only the columns we need in the above loop directly?
Yes. I considered alternatives, but all I could come up with was more code - without clear indication of performance improvements.
This solution uses more memory than necessary, but may be faster.


Reference Issues/PRs
Fixes #19627.
What does this implement/fix? Explain your changes.
This adds the possibility to pass a tuple
PolynomialFeatures(degree=(min_degree, max_degree)). Only terms with total degree=min_degreeare produced, except for the bias term, which is still controlled byinclude_bias.Examples:
degree=(2, 2),include_bias=True,interaction_only=Falsefor featuresA, Bwill generate:1, A**2, A*B, B**2degree=(2, 2),include_bias=False,interaction_only=Truefor featuresA, Bwill generate:A*BAny other comments?
The implementation could be more memory efficient, but I tried to make the code change not too large.