Skip to content

Commit 5ea46a5

Browse files
authored
DOC Ensures that PolynomialFeatures passes numpydoc validation (#21239)
1 parent 23afd5d commit 5ea46a5

File tree

2 files changed

+22
-23
lines changed

2 files changed

+22
-23
lines changed

maint_tools/test_docstrings.py

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
"OrthogonalMatchingPursuitCV",
2323
"PassiveAggressiveClassifier",
2424
"PassiveAggressiveRegressor",
25-
"PolynomialFeatures",
2625
"QuadraticDiscriminantAnalysis",
2726
"SelfTrainingClassifier",
2827
"SparseRandomProjection",

sklearn/preprocessing/_polynomial.py

+22-22
Original file line numberDiff line numberDiff line change
@@ -42,35 +42,35 @@ class PolynomialFeatures(TransformerMixin, BaseEstimator):
4242
----------
4343
degree : int or tuple (min_degree, max_degree), default=2
4444
If a single int is given, it specifies the maximal degree of the
45-
polynomial features. If a tuple ``(min_degree, max_degree)`` is
46-
passed, then ``min_degree`` is the minimum and ``max_degree`` is the
47-
maximum polynomial degree of the generated features. Note that
48-
min_degree=0 and 1 are equivalent as outputting the degree zero term
49-
is determined by ``include_bias``.
45+
polynomial features. If a tuple `(min_degree, max_degree)` is passed,
46+
then `min_degree` is the minimum and `max_degree` is the maximum
47+
polynomial degree of the generated features. Note that `min_degree=0`
48+
and `min_degree=1` are equivalent as outputting the degree zero term is
49+
determined by `include_bias`.
5050
5151
interaction_only : bool, default=False
52-
If true, only interaction features are produced: features that are
53-
products of at most ``degree`` *distinct* input features, i.e. terms
54-
with power of 2 or higher of the same input feature are excluded:
52+
If `True`, only interaction features are produced: features that are
53+
products of at most `degree` *distinct* input features, i.e. terms with
54+
power of 2 or higher of the same input feature are excluded:
5555
56-
- included: ``x[0]``, `x[1]`, ``x[0] * x[1]``, etc.
57-
- excluded: ``x[0] ** 2``, ``x[0] ** 2 * x[1]``, etc.
56+
- included: `x[0]`, `x[1]`, `x[0] * x[1]`, etc.
57+
- excluded: `x[0] ** 2`, `x[0] ** 2 * x[1]`, etc.
5858
5959
include_bias : bool, default=True
60-
If True (default), then include a bias column, the feature in which
60+
If `True` (default), then include a bias column, the feature in which
6161
all polynomial powers are zero (i.e. a column of ones - acts as an
6262
intercept term in a linear model).
6363
6464
order : {'C', 'F'}, default='C'
65-
Order of output array in the dense case. 'F' order is faster to
65+
Order of output array in the dense case. `'F'` order is faster to
6666
compute, but may slow down subsequent estimators.
6767
6868
.. versionadded:: 0.21
6969
7070
Attributes
7171
----------
7272
powers_ : ndarray of shape (`n_output_features_`, `n_features_in_`)
73-
powers_[i, j] is the exponent of the jth input in the ith output.
73+
`powers_[i, j]` is the exponent of the jth input in the ith output.
7474
7575
n_input_features_ : int
7676
The total number of input features.
@@ -98,7 +98,7 @@ class PolynomialFeatures(TransformerMixin, BaseEstimator):
9898
See Also
9999
--------
100100
SplineTransformer : Transformer that generates univariate B-spline bases
101-
for features
101+
for features.
102102
103103
Notes
104104
-----
@@ -181,6 +181,7 @@ def _num_combinations(
181181

182182
@property
183183
def powers_(self):
184+
"""Exponent for each of the inputs in the output."""
184185
check_is_fitted(self)
185186

186187
combinations = self._combinations(
@@ -199,8 +200,7 @@ def powers_(self):
199200
"in 1.2. Please use get_feature_names_out instead."
200201
)
201202
def get_feature_names(self, input_features=None):
202-
"""
203-
Return feature names for output features
203+
"""Return feature names for output features.
204204
205205
Parameters
206206
----------
@@ -211,6 +211,7 @@ def get_feature_names(self, input_features=None):
211211
Returns
212212
-------
213213
output_feature_names : list of str of shape (n_output_features,)
214+
Transformed feature names.
214215
"""
215216
powers = self.powers_
216217
if input_features is None:
@@ -238,7 +239,7 @@ def get_feature_names_out(self, input_features=None):
238239
input_features : array-like of str or None, default=None
239240
Input features.
240241
241-
- If `input_features` is `None`, then `feature_names_in_` is
242+
- If `input_features is None`, then `feature_names_in_` is
242243
used as feature names in. If `feature_names_in_` is not defined,
243244
then names are generated: `[x0, x1, ..., x(n_features_in_)]`.
244245
- If `input_features` is an array-like, then `input_features` must
@@ -270,14 +271,13 @@ def fit(self, X, y=None):
270271
"""
271272
Compute number of output features.
272273
273-
274274
Parameters
275275
----------
276276
X : {array-like, sparse matrix} of shape (n_samples, n_features)
277277
The data.
278278
279-
y : None
280-
Ignored.
279+
y : Ignored
280+
Not used, present here for API consistency by convention.
281281
282282
Returns
283283
-------
@@ -359,10 +359,10 @@ def transform(self, X):
359359
Returns
360360
-------
361361
XP : {ndarray, sparse matrix} of shape (n_samples, NP)
362-
The matrix of features, where NP is the number of polynomial
362+
The matrix of features, where `NP` is the number of polynomial
363363
features generated from the combination of inputs. If a sparse
364364
matrix is provided, it will be converted into a sparse
365-
``csr_matrix``.
365+
`csr_matrix`.
366366
"""
367367
check_is_fitted(self)
368368

0 commit comments

Comments
 (0)