Ridge regression
Penguin learning project
The project uses 342 complete Palmer penguin records: 240 training-pool and 102 held-out rows. The selected training rows determine feature scaling and model parameters. Source CSV
This project trains weights with softmax, unlike the homepage lab, which uses nearest species averages. Same penguin measurements; different classification methods. Predictions can differ.
Classification predicts three species; Ridge predicts body mass in grams using the same observations. These are separate models. Training predictions feed the objective; 102 separate test predictions never update the weights.
Objectives · Combine losses and penalties into a criterion for parameters or rules.
Project predictions and known answers produce losses. Classification uses cross-entropy and α/2 times squared non-bias weights; Ridge uses normalized-mass MSE and α times all squared coefficients, including the intercept.
Objective
- Input
- Mean training loss: ≈0.2556; Penalty: ≈0.0005264
- Output
- ≈0.2561
Project operation
The project calculation uses these records; the source formula and example follow below. Code edits run locally; project settings travel between pages.
Mean training loss → Objective → Gradient
Project input
Showing first three entries; the operation receives the complete array. Rounded preview; the operation uses full precision.
input.meanLoss· Mean training loss≈0.2556input.weights· Model[≈-2.422E-17, ≈0.2558, ≈0.679]input.alpha· Project settings or constant0.001input.task· Project settings or constantridge
Result
≈0.2561
Used in these source sections: 1.3 The questions ahead
The three invented training pairs give pack counts and known sticker counts: (1, 2), (2, 4), and (3, 6). In real applications, raw observations are collected and may be cleaned or turned into features; labels are known answers. Here the invented counts go directly into xs and ys without preprocessing.
With no intercept, the chosen weight is stickers per pack. Predict each count, square each error, and average the results. Add α times the squared weight.
The penalty favors smaller weights while the error measures fit.
Source formula example
exact · The result is exact for these finite toy inputs, apart from ordinary computer rounding.
Symbols
- Number of training examples.
- Input and target of example i.
- Real-valued weight vector; this toy has one entry.
- Nonnegative penalty strength.
Source formula example
This source example uses its own inputs and assumptions. Editing it does not change the project.
Edit a value or the code, then run the example. This is a finite demonstration, not a proof of the paper’s theorem.
Try weight 2. Which part of the score remains? Then set α to 0.
This example’s data flow
Code changed. Reset to restore this example’s data flow.
You choose
input.weight= 1input.alpha= 0.001
Initial values in code
xs=[1, 2, 3]ys=[2, 4, 6]
Calculated here
Result expression: evaluateRidge(xs, ys, input.weight, input.alpha)
weight←input.weightalpha←input.alpha
predictions=xs.map((x) => predict(x, weight))Uses:xs,predict,weighterrors=predictions.map((prediction, i) => prediction - ys[i])Uses:predictions,yssquaredErrors=errors.map(squaredLoss)Uses:errors,squaredLossmse=mean(squaredErrors)Uses:mean,squaredErrorspenalty=alpha * weight ** 2Uses:alpha,weight
Returns
xs- array (3 items): [1, 2, 3]
ys- array (3 items): [2, 4, 6]
predictions- array (3 items): [1, 2, 3]
errors- array (3 items): [-1, -2, -3]
squaredErrors- array (3 items): [1, 4, 9]
mse- ≈4.667
penalty- 0.001
objective- ≈4.668
Read numbers from input and return the result. JavaScript basics.
Result
Technical statement
This scores the reader-chosen weight; it does not fit a model or find the best weight. The reader also chooses α, whose default 0.001 comes from the source figure. An optimizer could use the objective to try another weight; a fitted weight could then predict a sticker count from a new pack count.
Source: Figure 1.4 · paper pp. 18