Overview
TheMultilinearRegression class implements multivariate (multiple output) linear regression, fitting k response variables simultaneously. It provides significant performance advantages over fitting k separate models by factoring the coefficient matrix only once.
Namespace: mlpp::regression
Template parameter:
Scalar- Floating-point type (float, double, long double). Defaults todouble.
Mathematical formulation
Solves the optimization problem:- X ∈ ℝⁿˣᵈ (feature matrix)
- Y ∈ ℝⁿˣᵏ (response matrix)
- W ∈ ℝᵈˣᵏ (coefficient matrix)
Constructor
Whether to fit a bias vector b ∈ ℝᵏ (one intercept per response)
L2 penalty λ ≥ 0 applied uniformly to all responses
Linear solver strategy:
SolveMethod::Auto- Chosen automatically (recommended)SolveMethod::Cholesky- Normal equations via LDLT; O(nd² + d²k)SolveMethod::SVD- Thin BDCSVD; O(nd·min(n,d))SolveMethod::JacobiSVD- Full-pivoting JacobiSVD (slowest, most stable)
Methods
fit
Feature matrix with shape (n_samples, n_features)
Response matrix with shape (n_samples, n_responses)
predict
Feature matrix with shape (n_samples, n_features)
Predicted matrix with shape (n_samples, n_responses)
score
Feature matrix
True response matrix
Mean R² score in the range (-∞, 1]. Higher values indicate better fit
score_per_response
Feature matrix
True response matrix
Vector of length n_responses where r2(k) = 1 - SS_res_k / SS_tot_k
residuals
Feature matrix
True response matrix
Residual matrix with shape (n_samples, n_responses). Requires fit()
gradient
Feature matrix
Response matrix
Gradient matrix with shape (n_features, n_responses). Requires fit()
coefficients
Coefficient matrix W ∈ ℝᵈˣᵏ in original (unscaled) feature space
intercepts
Bias vector b ∈ ℝᵏ with length n_responses. Zero vector if fit_intercept is false
is_fitted
True after a successful call to fit()
condition_number
Condition number σ_max/σ_min of the design matrix. Only available after an SVD solve
Usage example
Performance advantages
Compared to fitting k separateLinearRegression models:
- Cholesky solver: Factors XᵀX + nλI once, then solves k right-hand sides → O(nd² + d²k)
- SVD solver: Computes SVD of X once, then filters k response columns → O(nd·min(n,d) + nk·min(n,d))