Skip to main content

Constrained Models

Regression with coefficient constraints: bounded and non-negative solutions.


BLS - Bounded Least Squares

Constrained regression with coefficient bounds.

Parameters

ParameterTypeRequiredDefaultDescription
yDOUBLEYes-Target values
xLIST(DOUBLE)Yes-Predictors
optionsMAPYes-lower_bounds, upper_bounds, fit_intercept

Example

-- Elasticity must be negative (law of demand)
SELECT anofox_stats_bls_fit_agg(
log(quantity),
[log(price), log(income)],
MAP {
'lower_bounds': '[-5.0, 0.0]',
'upper_bounds': '[0.0, 3.0]'
}
) as model
FROM demand_data;

When to use BLS:

  • Economic constraints (negative elasticities)
  • Physical constraints (positive effects)
  • Domain knowledge requiring bounded coefficients

NNLS - Non-Negative Least Squares

Regression with non-negativity constraints on all coefficients.

Parameters

ParameterTypeRequiredDefaultDescription
yDOUBLEYes-Target values
xLIST(DOUBLE)Yes-Predictors
optionsMAPNo-fit_intercept (default: false), max_iterations, tolerance

Example

-- Channel contributions must be non-negative
SELECT
(model).coefficients[1] as search_contribution,
(model).coefficients[2] as social_contribution,
(model).coefficients[3] as email_contribution
FROM (
SELECT anofox_stats_nnls_fit_agg(
conversions,
[search_spend, social_spend, email_spend]
) as model
FROM marketing_data
);

When to use NNLS:

  • Marketing mix modeling (positive contributions only)
  • Spectral decomposition
  • Portfolio weights (no short selling)
🍪 Cookie Settings