Qu

ridge

Builtin index · Statistics & ML

result = ridge(X, y, alpha)

Input: X, y, alpha · Output: result

What it is

Tikhonov-regularized (L2) least squares on an N-row, D-column feature matrix X and a length-N target vector y, with regularization strength alpha (a non-negative number; plain OLS at alpha = 0).

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
result = ridge(X, y, alpha)
X matrix, vector, or numberTikhonov-regularized (L2) least squares on an N-row, D-column feature matrix X and a length-N target vector y, with regularization strength alpha (a non-negative number.
y matrix, vector, or numberTikhonov-regularized (L2) least squares on an N-row, D-column feature matrix X and a length-N target vector y, with regularization strength alpha (a non-negative number.
alpha —plain OLS at alpha = 0).
result vector
Returns only the length-D coefficient vector, with no intercept term.

Examples

From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.

X    = randn(120, 3, seed = 3)
beta = [2.0, -1.0, 0.5]
y    = X * beta + 0.1 * randn(120, seed = 4)
c = ridge(X, y, 0.5)
print("ridge coef: {round(c, 3)}")   # close to [2.0, -1.0, 0.5]

output
ridge coef: [1.993, -1.002, 0.496]

from statistics-ml