University · Lesson 4 · Sports Analytics
Linear Regression
Learn how simple linear regression fits a line to data. Use baseball win percentages to understand slope, intercept, least squares, and residuals.
Lychee University · Lesson 4
Last lesson, we compared two numbers.
A baseball team’s actual win percentage.
And its Pythagorean expectation—the win percentage estimated from runs scored and runs allowed.
We plotted one on the horizontal axis and the other on the vertical axis.
Each dot was one team’s season.
Now we want to describe the relationship between those numbers.
That’s where linear regression comes in.
From dots to a line
Look at the scatter plot.
As the scoring-based estimate rises, does actual win percentage tend to rise too?
A straight line can help us describe that pattern.
But where should we put it?
We could draw one by eye.
Someone else might draw it a little higher. Or give it a different slope.
Linear regression gives us a consistent way to fit that line using the data.
With one input variable and one outcome, we call it simple linear regression.
Here, the input is Pythagorean expectation.
The outcome is actual win percentage.
Where should the line go?
Simple linear regression
Input: Pythagorean expectation
Outcome: actual win %
The regression equation
The fitted line has a simple equation:
The intercept sets the line’s height.
The slope tells us how much the fitted outcome changes as the input increases.
Let’s use a made-up equation:
These numbers are just for illustration. We haven’t fitted them to a real season.
Use decimals for the percentages.
For a team with a Pythagorean expectation of sixty percent:
The line gives us an estimated actual win percentage of fifty-nine percent.
The regression equation
Estimated actual win % =
0.05 + 0.90 × Pyth. exp.
Intercept
Sets the line's height. Change it and the whole line slides up or down.
Slope
How much the fitted outcome changes as the input increases: 0.90 up for every 1 across.
0.05 + 0.90 × 0.60
= 0.05 + 0.54
= 0.59
Estimated actual win percentage
59%
The slope, 0.90, means a one-percentage-point increase in Pythagorean expectation corresponds to a 0.9-percentage-point increase along this fitted line.
Build the line
Estimated actual win %
0.05 + 0.90 × 0.60 = 0.59
59.0%
Each 1-point rise in Pythagorean expectation adds 0.90 points along this line.
And the intercept?
It gives the line’s value when the input is zero.
That helps position the line mathematically. It may have little practical meaning when zero is far outside the data we’re studying.
What is the intercept?
Our data
Pythagorean expectation runs from about 37% to 62%.
The intercept: 0.05
The line's value when the input is zero.
Useful, not meaningful here
It positions the line mathematically. A team expected to win 0% of its games is nowhere near our data.
How do we choose the line?
For each team, compare its actual win percentage with the value on the line.
That vertical difference is called a residual.
Suppose our example team actually won sixty-two percent of its games.
The line gave us fifty-nine percent.
Its residual is positive three percentage points.
The dot sits above the fitted line.
If it actually won fifty-six percent, its residual would be negative three percentage points.
Below the line.
Actual vs fitted
Pyth. exp.
60%
Actual
62%
Fitted value (on the line)
0.05 + 0.90 × 0.60 = 0.59
Residual = actual − fitted
0.62 − 0.59 = +0.03
+3.0 pts
Positive residual: the dot sits above the fitted line.
A common fitting method is ordinary least squares.
It squares each residual, adds those squared values together, and chooses the line with the smallest total.
Squaring keeps positive and negative differences from cancelling out.
It also gives larger differences more weight.
Problem: raw residuals cancel
Bonus: bigger misses weigh more
A miss of 4 counts 16 times as much as a miss of 1.
That’s what “best fit” means here: the smallest sum of squared vertical differences.
Your line
0.31 + 0.40 × Pyth. exp.
Sum of squared residuals
122.4
squared percentage points
Smallest possible: 31.4
90.9 above the smallest total. Keep adjusting, or let least squares do it.
Two lines, two questions
Remember the diagonal from lesson 3?
That line marked where actual win percentage equalled Pythagorean expectation.
Sixty percent across. Sixty percent up.
We chose that line as a reference.
The regression line is fitted from the dots.
The equality line asks:
Did this team’s record match its scoring-based estimate?
The regression line asks:
Where does this team sit compared with the relationship fitted across the teams in our data?
Two lines, two questions
Equality line · we chose it
Did this team's record match its scoring-based estimate?
Regression line · fitted
Where does this team sit compared with the relationship fitted across the teams?
Summit: below one line, above the other. Different comparisons.
A team can sit above one line and below the other.
They’re different comparisons.
Selected team
Summit
62.1% → 59.9%
vs equality line (actual − expected)
−2.3 pts · below
vs regression line (actual − fitted)
+0.6 pts · above
fitted value 59.3%
Opposite sides: below one line, above the other.
What the fitted line tells us
We now have an equation describing how the two numbers relate in our sample.
But the dots still matter.
Some may sit close to the line.
Others may be much farther away.
A fitted value is an estimate. Individual teams can finish above or below it.
Same line, different spread
Fitted line (unchanged)
0.112 + 0.77 × x
Largest miss
2.9 pts
Within 1 pt
6 of 16
The shaded band is the typical distance from the line: 1.6 points. A fitted value is an estimate; individual teams land above or below it.
And fitting a line to one season doesn’t show how accurately it will predict another.
That takes a separate check using data the model hasn’t already seen.
Fit vs check
Season the line was fitted on
—
typical miss
A season it hasn't seen
?
typical miss
How well a line fits its own data doesn't tell you how well it predicts new data.
For now, we’ve taken the next step.
First, a table.
Then, a scatter plot.
Now, a line fitted to the data.
1 · First, a table
…and 6 more
2 · Then, a scatter plot
3 · Now, a fitted line
We can describe the relationship with numbers—and measure how far each team sits from that line.
Sources
Get started with Lychee.
Free to explore here · Polymarket, Kalshi, Chainlink & more