All lessons

University · Lesson 4 · Sports Analytics

misterrpink

misterrpink

Nov 7, 2026 · 8 min read

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.

Hypothetical 12-team league from lesson 3. Everyone draws a slightly different line by eye; regression fits one from the data.

The regression equation

The fitted line has a simple equation:

Estimated actual win percentage=intercept+slope×Pythagorean expectation\text{Estimated actual win percentage} = \text{intercept} + \text{slope} \times \text{Pythagorean expectation}

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:

Estimated actual win percentage=0.05+0.90×Pythagorean expectation\text{Estimated actual win percentage} = 0.05 + 0.90 \times \text{Pythagorean expectation}

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:

0.05+0.90×0.60=0.590.05 + 0.90 \times 0.60 = 0.59

The line gives us an estimated actual win percentage of fifty-nine percent.

Made-up numbers for illustration, not fitted to a real season. Percentages go into the equation as decimals.

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

0.05
0.90
0.60

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.

Move the sliders. The faint dashed line is the equality line from lesson 3, for reference.

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.

The intercept positions the line. Read literally, it describes a team expected to win 0% of its games, which 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.

Residual=actual value−fitted value\text{Residual} = \text{actual value} - \text{fitted value}

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.

45%45%50%50%55%55%60%60%65%65%70%70%Pythagorean expectation →Actual win % →fitted line+3.0 pts

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.

Drag the team's dot, or focus it and use the arrow keys. The line is the made-up equation: 0.05 + 0.90 × Pythagorean expectation.

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.

Squared residuals can't cancel, and big misses count for much more than small ones.

That’s what “best fit” means here: the smallest sum of squared vertical differences.

35%35%40%40%45%45%50%50%55%55%60%60%65%65%Pythagorean expectation →Actual win % →

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.

Drag the two round handles to move the line, or focus one and use the arrow keys. Squares show each squared residual; least squares makes their total area as small as possible.

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?

Hypothetical league. Summit sits below the equality line and above the regression line at the same time.

A team can sit above one line and below the other.

They’re different comparisons.

35%35%40%40%45%45%50%50%55%55%60%60%65%65%Pythagorean expectation →Actual win % →Summit

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.

Hypothetical league. Hover or tap a dot to measure it against both lines.

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

1.6 pts

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.

Hypothetical teams. The slider scales how far each dot sits from the line; the fitted line itself stays the same at every setting.

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.

Hypothetical seasons. “Typical miss” is the root-mean-square residual. Checking a line needs data it wasn't fitted on.

For now, we’ve taken the next step.

First, a table.

Then, a scatter plot.

Now, a line fitted to the data.

First a table, then a scatter plot, now a line fitted to the data, plus how far each team sits from it.

We can describe the relationship with numbers—and measure how far each team sits from that line.

Sources