ridge_model
Builtin index · Statistics & ML
result = ridge_model(X, y, alpha)
Input: X, y, alpha · Output: result
What it is
The same fit as ols_model on an N-row, D-column X and a length-N y, but with L2 regularization strength alpha (a non-negative number) shrinking the coefficients toward zero; ols_model is this at alpha = 0.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = ridge_model(X, y, alpha) | X numberThe same fit as ols_model on an N-row, D-column X and a length-N y, but with L2 regularization strength alpha (a non-negative number) shrinking the coefficients toward zero.y numberThe same fit as ols_model on an N-row, D-column X and a length-N y, but with L2 regularization strength alpha (a non-negative number) shrinking the coefficients toward zero.alpha —ols_model is this at alpha = 0. | result Record | Returns a fitted model Record with the same fields as ols_model. |
Examples
From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.
r = ridge_model(X, y, 0.1) # least squares with L2 regularization
k = kmeans_model(X, 2, seed = 42) # .predict assigns to the nearest centroid
p = pca_model(X, 1) # .predict projects onto the fitted components
print("cluster of row 0: {k.predict(X)[0]}")
cluster of row 0: 1
from specialized
centre(X) := X - mean(X)
final(X, y) := ridge_model(X, y, 0.1)
pipe = pipeline("centre", "final")
fitted = pipe.fit(X, y)
print("pipeline R^2 {fitted.score(X, y):.4f}")
pipeline R^2 0.9992
from specialized
standardize_cols(M) := (M - mean(M)) ./ std(M)
final(A, b) := ridge_model(A, b, 0.1)
pipe = pipeline("standardize_cols", "final")
fitted = pipe.fit(split.X_train, split.y_train)
print("held-out R2: {round(fitted.score(split.X_test, split.y_test), 4)}")
held-out R2: 0.991
from statistics-ml
How it works
ridge_model(X, y, alpha) — ols_model plus L2 regularization on the centered design, the model-protocol sibling of the flat ridge builtin (which has no automatic intercept).
From the note above this builtin in the interpreter, where the reasoning was written down as it was built.