Skip to content

Commit 0ec12eb

Browse files
AWNystromjnothman
authored andcommitted
DOC Updating PolynomialFeatures.Transform docstring (scikit-learn#13755)
1 parent 51d25d7 commit 0ec12eb

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

sklearn/preprocessing/data.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1475,17 +1475,21 @@ def transform(self, X):
14751475
14761476
Parameters
14771477
----------
1478-
X : array-like or sparse matrix, shape [n_samples, n_features]
1478+
X : array-like or CSR/CSC sparse matrix, shape [n_samples, n_features]
14791479
The data to transform, row by row.
1480-
Sparse input should preferably be in CSR format (for speed),
1481-
but must be in CSC format if the degree is 4 or higher.
1482-
1483-
If the input matrix is in CSR format and the expansion is of
1484-
degree 2 or 3, the method described in the work "Leveraging
1485-
Sparsity to Speed Up Polynomial Feature Expansions of CSR
1486-
Matrices Using K-Simplex Numbers" by Andrew Nystrom and
1487-
John Hughes is used, which is much faster than the method
1488-
used on CSC input.
1480+
1481+
Prefer CSR over CSC for sparse input (for speed), but CSC is
1482+
required if the degree is 4 or higher. If the degree is less than
1483+
4 and the input format is CSC, it will be converted to CSR, have
1484+
its polynomial features generated, then converted back to CSC.
1485+
1486+
If the degree is 2 or 3, the method described in "Leveraging
1487+
Sparsity to Speed Up Polynomial Feature Expansions of CSR Matrices
1488+
Using K-Simplex Numbers" by Andrew Nystrom and John Hughes is
1489+
used, which is much faster than the method used on CSC input. For
1490+
this reason, a CSC input will be converted to CSR, and the output
1491+
will be converted back to CSC prior to being returned, hence the
1492+
preference of CSR.
14891493
14901494
Returns
14911495
-------

0 commit comments

Comments
 (0)