Overview
ThePolynomialRegression class composes polynomial feature expansion with linear regression to fit polynomial models. It automatically expands input features to polynomial terms and fits a linear model in the expanded space.
Namespace: mlpp::regression
Template parameter:
Scalar- Floating-point type (float, double, long double). Defaults todouble.
Mathematical formulation
The model fits:- Pure powers (
include_interactions=false): Appends x₁, x₁², …, x₁ᴰ, x₂, …, xᵈᴰ - Full interaction terms (
include_interactions=true): All monomials with degree sum ≤ D
Constructor
Maximum polynomial degree D ≥ 1
Whether to include cross-feature monomials (e.g., x₁·x₂). When false, only pure powers are used
Whether to fit a bias term. Forwarded to the underlying LinearRegression
L2 penalty λ ≥ 0. Forwarded to the underlying LinearRegression
Solver strategy forwarded to LinearRegression:
SolveMethod::Auto- Chosen automatically (recommended)SolveMethod::Cholesky- Normal equations via LDLTSolveMethod::SVD- Thin BDCSVDSolveMethod::JacobiSVD- Full-pivoting JacobiSVD
Methods
fit
Feature matrix with shape (n_samples, n_features)
Target vector with length n_samples
predict
Feature matrix with shape (n_samples, n_features)
Predicted values with length n_samples
score
Feature matrix
True target values
R² score in the range (-∞, 1]
residuals
Feature matrix
True target values
Residual vector with length n_samples
coefficients
Coefficients of the underlying linear model in the expanded feature space
intercept
Intercept of the underlying linear model
is_fitted
True after a successful call to fit()
features
Reference to the underlying polynomial feature transformer
regressor
Reference to the underlying linear regression model
PolynomialFeatures
The underlying feature transformer can also be used independently:Constructor
Maximum monomial degree D ≥ 1
Whether to prepend a constant-1 column
Whether to include cross-feature monomials
transform
Input matrix with shape (n_samples, n_features)
Expanded matrix with shape (n_samples, output_dim(n_features))
output_dim
Number of input features
Number of output columns after polynomial expansion