ridge_regression

Function ridge_regression 

Source
pub fn ridge_regression(
    y_json: &str,
    x_vars_json: &str,
    _variable_names: &str,
    lambda: f64,
    standardize: bool,
) -> String
Expand description

Performs Ridge regression via WASM.

Ridge regression adds an L2 penalty to the coefficients, which helps with multicollinearity and overfitting. The intercept is never penalized.

§Arguments

  • y_json - JSON array of response variable values
  • x_vars_json - JSON array of predictor arrays
  • variable_names - JSON array of variable names
  • lambda - Regularization strength (>= 0, typical range 0.01 to 100)
  • standardize - Whether to standardize predictors (recommended: true)

§Returns

JSON string containing:

  • lambda - Lambda value used
  • intercept - Intercept coefficient
  • coefficients - Slope coefficients
  • fitted_values - Predictions on training data
  • residuals - Residuals (y - fitted_values)
  • df - Effective degrees of freedom

§Errors

Returns a JSON error object if parsing fails, lambda is negative, or domain check fails.