liveBook · Manning

Mean

As explained in Grokking AI Algorithms, Second Edition

A mean is the arithmetic average of a set of numerical values.

A mean is an arithmetic average: add the available numerical values, then divide by how many values you added. It gives you one number to use as a reference point for the group. section 8.8

Finding the center of diamond data

Suppose carat values are recorded in thousandths of a carat. For ten diamonds, the mean carat value is 1,229 (or 1.229 carats), and the mean price is 3,431. A diamond recorded as 300 with a price of 339 sits 929 below the carat mean and 3,092 below the price mean. Subtracting each mean makes it easier to see how carat and price move together. section 8.11

Table 8.9 The diamond dataset and calculations, part 1

Carat (x)

Price (y)

x – mean of x

y – mean of y

1

300

339

300 – 1,229

-929

339 – 3,431

-3,092

2

410

561

410 – 1,229

-819

561 – 3,431

-2,870

3

750

2,760

750 – 1,229

-479

2,760 – 3,431

-671

4

910

2,763

910 – 1,229

-319

2,763 – 3,431

-668

5

1,200

2,809

1,200 – 1,229

-29

2,809 – 3,431

-622

6

1,310

3,697

1,310 – 1,229

81

3,697 – 3,431

266

7

1,500

4,022

1,500 – 1,229

271

4,022 – 3,431

591

8

1,740

4,677

1,740 – 1,229

511

4,677 – 3,431

1,246

9

1,960

6,147

1,960 – 1,229

731

6,147 – 3,431

2,716

10

2,210

6,535

2,210 – 1,229

981

6,535 – 3,431

3,104

1,229

3,431

Means

Follow the carat and price columns across to see each value compared with its feature's mean. section 8.11

In a simple linear-regression calculation, find the mean of the input values and the mean of the prices separately. Subtract the appropriate mean from each value, then use those differences to calculate the line's slope and intercept. In Python, each mean starts with the same pattern: `sum(values) / len(values)`. section 8.11

A mean is useful, but check what the numbers represent before using it:

  • For a missing numerical value, the feature's mean is an easy replacement. It may be misleading if that feature is related to another one: replacing a missing carat value with the mean ignores its relationship with price. It cannot fill a categorical value such as cut or clarity. section 8.8
  • For neural-network activations, the mean describes the average result of nodes in a layer. A weight-initialization rule of thumb aims for a mean of zero, alongside consistent variance. section 9.14

How Grokking AI Algorithms, Second Edition covers it

How deep it goes
Defines the arithmetic calculation and works through feature means and deviations before using them in a Python regression function.
Examples
Uses missing diamond features and a ten-diamond carat–price table with means of 1,229 and 3,431.
What it assumes
Assumes basic addition, division, and numerical data; defines the mean before applying it to data preparation and regression.
What you can do after
Apply it via arithmetic or Python to calculate feature averages, assess mean replacement, and center values for a regression line.
How it connects
Connects the mean to missing-data imputation, median, linear regression, weight initialization, and variance.

Also explained in

Compare how 29 books explain mean →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking AI Algorithms, Second Edition. The section links point to the parts of the book it draws on.