PolynomialFeatures¶
yohou.preprocessing.sklearn_wrappers.PolynomialFeatures
¶
Bases: SklearnTransformer
Generate polynomial and interaction features.
Generate a new feature matrix consisting of all polynomial combinations of the features with degree less than or equal to the specified degree.
For example, if an input sample is two dimensional and of the form
[a, b], the degree-2 polynomial features are [1, a, b, a^2, ab, b^2].
This is a Yohou wrapper that preserves the polars DataFrame structure and "time" column.
Parameters¶
| Name | Type | Description | Default |
|---|---|---|---|
degree
|
int or tuple(min_degree, max_degree)
|
If a single int is given, it specifies the maximal degree of the
polynomial features. If a tuple |
2
|
interaction_only
|
bool
|
If True, only interaction features are produced: features that are
products of at most |
False
|
include_bias
|
bool
|
If True, then include a bias column, the feature in which all polynomial powers are zero. |
True
|
order
|
('C', 'F')
|
Order of output array in the dense case. 'F' order is faster to compute, but may slow down subsequent estimators. |
'C'
|
Attributes¶
| Name | Type | Description |
|---|---|---|
instance_ |
PolynomialFeatures
|
The fitted sklearn PolynomialFeatures instance. |
n_features_in_ |
int
|
Number of features seen during fit. |
n_output_features_ |
int
|
The total number of polynomial output features. |
Examples¶
>>> import polars as pl
>>> from datetime import datetime
>>> from yohou.preprocessing import PolynomialFeatures
>>> X = pl.DataFrame({
... "time": [datetime(2024, 1, i) for i in range(1, 4)],
... "a": [1.0, 2.0, 3.0],
... "b": [2.0, 3.0, 4.0],
... })
>>> poly = PolynomialFeatures(degree=2, include_bias=False)
>>> poly.fit(X)
PolynomialFeatures(...)
>>> X_poly = poly.transform(X)
>>> # Generates: a, b, a^2, a*b, b^2
>>> len(X_poly.columns) > len(X.columns)
True
See Also¶
SplineTransformer: Generate spline basis features.
Source Code¶
Show/Hide source
489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 | |
Methods¶
Tutorials¶
The following example notebooks use this component:
-
How to Use Scikit-learn Scalers
Data-Features
Wrap sklearn scalers (StandardScaler, MinMaxScaler, RobustScaler, PowerTransformer, PolynomialFeatures) for polars DataFrames with inverse transforms.