Thanks to visit codestin.com
Credit goes to github.com

Skip to content

ENH PolynomialFeatures better handle degree=0 - #23370

Merged
adrinjalali merged 7 commits into
scikit-learn:mainfrom
MaxwellLZH:fix/poly-zero-degree
May 16, 2022
Merged

ENH PolynomialFeatures better handle degree=0#23370
adrinjalali merged 7 commits into
scikit-learn:mainfrom
MaxwellLZH:fix/poly-zero-degree

Conversation

@MaxwellLZH

Copy link
Copy Markdown
Contributor

Reference Issues/PRs

Fixes #19551 .

What does this implement/fix? Explain your changes.

This PR makes the following two changes:

  1. When degree=0, a ValueError will be raised if include_bias=False, a single constant column will be returned if include_bias=True regardless of the input number of features
  2. Fixes an edge case. When passing in a sparse matrix, the output of degree=0, include_bias=True used to have n+1 columns with n being number of input features, now it outputs 1 column correctly.

@MaxwellLZH

Copy link
Copy Markdown
Contributor Author

Hi @adrinjalali , could you help take a look at this PR if you got time? Thank you!

@lorentzenchr lorentzenchr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@MaxwellLZH Thanks for working on this issue. Here are some small review comments.

Comment thread sklearn/preprocessing/_polynomial.py Outdated
Comment thread sklearn/preprocessing/_polynomial.py Outdated
Comment thread sklearn/preprocessing/_polynomial.py
Comment thread sklearn/preprocessing/tests/test_polynomial.py Outdated
MaxwellLZH and others added 3 commits May 14, 2022 20:54
Co-authored-by: Christian Lorentzen <[email protected]>
Co-authored-by: Christian Lorentzen <[email protected]>

@lorentzenchr lorentzenchr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM. This PR needs a whatsnew entry for version 1.2.

@adrinjalali
adrinjalali merged commit 8fe9e24 into scikit-learn:main May 16, 2022
glemaitre pushed a commit to glemaitre/scikit-learn that referenced this pull request May 19, 2022
* raise error for PolynomialFeature when include_bias=False and degree=0

* better error message

Co-authored-by: Christian Lorentzen <[email protected]>

* use elif

Co-authored-by: Christian Lorentzen <[email protected]>

* address comments

* add whatsnew

* fix typo

Co-authored-by: Christian Lorentzen <[email protected]>
glemaitre pushed a commit that referenced this pull request May 19, 2022
* raise error for PolynomialFeature when include_bias=False and degree=0

* better error message

Co-authored-by: Christian Lorentzen <[email protected]>

* use elif

Co-authored-by: Christian Lorentzen <[email protected]>

* address comments

* add whatsnew

* fix typo

Co-authored-by: Christian Lorentzen <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PolynomialFeatures doesn't work correctly when degree=0

3 participants