PolynomialFeatures
Generates a new feature matrix consisting of all polynomial combinations of the input features up to a given degree. This enables fitting polynomial relationships with a linear model.
Feature Expansion
For input features with degree and bias:
The number of output features is:
where is the number of input features and is the degree. For example, produces features.
Interaction Only
When interaction_only = true, only interaction features are generated (no powers for ). For with , this yields .
Usage with Linear Models
Polynomial features combined with a linear model create a polynomial regression pipeline:
auto pipe = Skigen::make_pipeline(
Skigen::PolynomialFeatures<>(3),
Skigen::LinearRegression<>()
);
This fits while keeping the model linear in the parameters.
Mirrors sklearn.preprocessing.PolynomialFeatures.
Constructor
Skigen::PolynomialFeatures<Scalar> poly(int degree = 2,
bool include_bias = true,
bool interaction_only = false);
| Parameter | Default | Description |
|---|---|---|
degree | 2 | Maximum polynomial degree |
include_bias | true | Include a bias column of ones |
interaction_only | false | Only interaction features (no powers) |
Methods
| Method | Description |
|---|---|
fit(X) | Compute output feature structure |
transform(X) | Generate polynomial features |
fit_transform(X) | Fit and transform in one call |
Fitted Attributes
| Accessor | Type | Description |
|---|---|---|
n_output_features() | Eigen::Index | Number of output features |
Example
#include <Skigen/Preprocessing>
// X has 2 features → degree=2 generates: 1, x1, x2, x1², x1·x2, x2²
Skigen::PolynomialFeatures poly(2);
auto X_poly = poly.fit_transform(X);