2.2.8 · D1Linear & Logistic Regression

Foundations — R-squared and adjusted R-squared

1,624 words7 min readBack to topic

Before you can trust the formula you need to know what every single symbol in it means as a picture, not as a squiggle. Below we unpack them one at a time, each building on the last. Nothing is used before it is drawn.


1. The data points:

Picture it: scatter a handful of dots on a graph. Each dot's height is one . That's all a dataset is — a bunch of heights.

Why the topic needs it: these are the truths the model is trying to reproduce. Everything else — the average, the misses, the score — is built by comparing things to these dots.

Figure — R-squared and adjusted R-squared

2. The counter and the summation sign: and

Why the topic needs it: is built from sums over every data point. Without we could not write "add up all the misses" compactly.


3. The average:

Picture it: draw one flat horizontal line through the middle of your dots. That line is . It's the "I know nothing, so I'll just guess the average for everyone" line.

Figure — R-squared and adjusted R-squared

4. The model's guesses:

Picture it: if the model is a straight line (as in Linear Regression), then is the height of that sloped line directly above data point .

Why the topic needs it: the whole point of is to compare the guesses against the truths . Both symbols must be crystal clear before we can talk about "error."


5. A single miss: the residual

Why we square it — squaring is the tool, and here's why that tool: if we just added raw residuals, the positive ones () and negative ones () would cancel and hide the errors, wrongly reporting "no error." Squaring turns every gap positive (a negative times a negative is positive) and punishes big misses more than small ones ( vs ). This is exactly the idea behind Mean Squared Error.

Figure — R-squared and adjusted R-squared

6. Adding up the squared misses: and

Now we combine everything: the counter, the sum, the mean, the guesses, and the squaring.

Figure — R-squared and adjusted R-squared

Now the master formula reads in plain English: If the model kills most of the error, the fraction is near , so is near . If the model does no better than the average, , the fraction is , and .


7. The bookkeeping symbols for adjusted : and degrees of freedom


How these foundations feed the topic

y_i true values

y-bar the mean

y-hat model guesses

sum sigma over n points

SS_tot total spread

SS_res leftover error

squaring the misses

R-squared score

p feature count

degrees of freedom

Adjusted R-squared


Equipment checklist

Test yourself — cover the right side and answer out loud.

What does the little in mean?
A counter that labels which data point you mean (1st, 2nd, ... up to ).
What does do?
Plugs into the expression and adds every result into one total.
What picture is ?
A single flat horizontal line at the average height — the "guess the average for everyone" baseline.
Truth vs guess: which symbol has the hat?
The guess wears the hat; the truth is bare.
What is a residual, in words?
Truth minus guess, — the vertical gap between a real dot and the model's line.
Why do we square the residuals instead of just adding them?
So positive and negative misses don't cancel, and big misses get punished more.
What line does measure gaps to?
The flat average line .
What line does measure gaps to?
The model's prediction line .
In plain words, what is ?
How much smaller the model made the total squared error compared to the do-nothing average baseline.
What does count, and why do we track it?
The number of features (knobs); tracking it lets adjusted charge a penalty for adding useless features.