You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/modules/preprocessing.rst
+38Lines changed: 38 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -426,3 +426,41 @@ values than observed values.
426
426
427
427
:class:`Imputer` can be used in a Pipeline as a way to build a composite
428
428
estimator that supports imputation. See :ref:`example_missing_values.py`
429
+
430
+
.. _polynomial_features:
431
+
432
+
Generating polynomial features
433
+
==============================
434
+
435
+
Often it's useful to add complexity to the model by considering nonlinearity within input data. One basic representation is to use polynomial to get features' high-order and interaction terms, which is implemented in :class:`PolynomialFeatures`::
436
+
437
+
>>> import numpy as np
438
+
>>> from sklearn.preprocessing import PolynomialFeatures
439
+
>>> X = np.arange(6).reshape(3, 2)
440
+
>>> X # doctest: +ELLIPSIS
441
+
array([[0, 1],
442
+
[2, 3],
443
+
[4, 5]])
444
+
>>> poly = PolynomialFeatures(2)
445
+
>>> poly.fit_transform(X) # doctest: +ELLIPSIS
446
+
array([[ 1, 0, 1, 0, 0, 1],
447
+
[ 1, 2, 3, 4, 6, 9],
448
+
[ 1, 4, 5, 16, 20, 25]])
449
+
450
+
The features of X have been transformed from :math:`(X_1, X_2)` to :math:`(1, X_1, X_2, X_1^2, X_1X_2, X_2^2)`.
451
+
452
+
In some cases, only interaction terms among features are required, and it can be gotten with the setting ``interaction_only=True``::
0 commit comments