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

Skip to content

PolynomialFeatures doesn't work correctly when degree=0 #19551

Description

@kbattocchi

Describe the bug

PolynomialFeatures.transform fails when degree=0 and the input has more than one column.

Steps/Code to Reproduce

from sklearn.preprocessing import PolynomialFeatures
PolynomialFeatures(degree=0, include_bias=True).fit_transform(np.ones((10,1))) # works
PolynomialFeatures(degree=0, include_bias=False).fit_transform(np.ones((10,1))) # works
PolynomialFeatures(degree=0, include_bias=True).fit_transform(np.ones((10,2))) # raises a ValueError due to a broadcasting problem
PolynomialFeatures(degree=0, include_bias=False).fit_transform(np.ones((10,2))) # raises a ValueError due to a broadcasting problem

Expected Results

No error is raised by any of the examples.

Actual Results

Transforming an array with more than one column fails.

Versions

System:
python: 3.6.6 (v3.6.6:4cf1f54eb7, Jun 27 2018, 03:37:03) [MSC v.1900 64 bit (AMD64)]
executable: C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\python.exe
machine: Windows-10-10.0.19041-SP0

Python dependencies:
pip: 21.0.1
setuptools: 51.0.0
sklearn: 0.24.1
numpy: 1.18.5
scipy: 1.5.4
Cython: 0.29.14
pandas: 1.0.5
matplotlib: None
joblib: 1.0.0
threadpoolctl: 2.1.0

Built with OpenMP: True

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions