← All posts

AI basics › From statistics to AGI

What is statistics? A gentle guide to learning from data

What statistics is, told through samples, confidence intervals, p-values, and regression, with a small Python example and why AI starts here.

The word statistics turns up in more places than you might expect. A news story says a poll has a margin of error of three points, a drug trial reports a statistically significant result, and an app tests two versions of a button to see which one people tap more. And if you’ve looked at a roadmap for learning AI, you may have noticed statistics sitting near the very start. Still, if someone asked what statistics actually is, perhaps “the subject with averages and charts” is all that comes to mind.

Statistics is the discipline of collecting data, summarizing it, and drawing conclusions from it when you can’t be certain. We rarely get to see everything we care about, so conclusions have to come from a part. That’s why statistics tells you what the data in front of you says and also how far that conclusion might be from the truth. The second part is easy to forget, and it’s also why the word keeps coming up around AI. Machine learning, which much of today’s AI is built on, also learns from a sample of data and then has to work on data it has never seen. This is the first post in the series “From statistics to AGI,” so toward the end I’ll come back to why the road to AI starts here.

Describing what you have, and reaching beyond it

Statistics has two broad halves. Descriptive statistics summarizes the data you have, with numbers such as the average and with charts. Inferential statistics uses that data to say something about a larger group you haven’t fully observed. A poll that asks a thousand people and then talks about all voters is doing inference.

Two terms come up again and again. The population is the whole group you want to know about, such as every user of an app. The sample is the part you actually observe, such as the 30 users who answered your survey. If the sample is picked at random, it tends to look like a small copy of the population, and that’s what lets you reason from the sample to the population.

When you look at a sample, the first thing to see is its distribution, which is simply how the values are spread out. Two numbers are enough to start describing it. The mean is the center, the ordinary average. The standard deviation measures how far values typically sit from that mean, so a small one means the values bunch together and a large one means they’re spread out. For a sample, the standard deviation is usually computed by dividing by one less than the number of values, because a sample tends to look a little less spread out than its population. Python’s statistics module keeps the two apart as stdev for a sample and pstdev for a whole population.

Thirty users and their daily app time

Let’s make this concrete. The code below creates a made-up app with 100,000 users and picks 30 of them at random. Each user has two numbers, push notifications received per day and minutes spent in the app per day. In real life you’d only see the 30, but because we build the population ourselves, we can check our conclusions against the truth later. The seed is fixed, so you’ll get the same numbers when you run it.

import numpy as np
from scipy import stats

rng = np.random.default_rng(seed=2026)

# A made-up app with 100,000 users (the population)
notifs_all = rng.integers(0, 41, size=100_000)  # push notifications per day
noise = rng.normal(0, 10, size=100_000)
minutes_all = (15 + 1.2 * notifs_all + noise).clip(min=0)  # minutes in the app per day

# The sample: 30 users picked at random
pick = rng.choice(100_000, size=30, replace=False)
notifs, minutes = notifs_all[pick], minutes_all[pick]

counts, edges = np.histogram(minutes, bins=range(0, 81, 20))
for c, e in zip(counts, edges):
    print(f"{e:>2}-{e + 20:<2} min | {'#' * c}")
print(f"mean {minutes.mean():.1f} min, sd {minutes.std(ddof=1):.1f} min")
 0-20 min | #####
20-40 min | ##########
40-60 min | ###########
60-80 min | ####
mean 40.1 min, sd 17.7 min

Each row is a 20-minute range and each # is one person, so this is the sample’s distribution drawn in text. Most people fall between 20 and 60 minutes, with a few on either side. The mean is 40.1 minutes, and the standard deviation of 17.7 minutes says a typical user sits roughly 18 minutes away from that mean. ddof=1 is the setting that divides by one less than the number of values.

Estimates and confidence intervals

The sample mean of 40.1 minutes is our estimate of the population mean, the number we actually want. But a different 30 people would have given a different number, so this number alone doesn’t say how much to trust it. A confidence interval attaches that uncertainty to it. It’s the sample mean plus or minus a margin, and the margin grows when the data is more spread out and shrinks as the sample gets bigger. The code below builds that margin from the standard error, the standard deviation divided by the square root of the sample size, times a multiplier from the t distribution. It’s the same recipe the NIST/SEMATECH e-Handbook gives.

def mean_ci(x, level=0.95):
    return stats.t.interval(level, df=len(x) - 1, loc=np.mean(x), scale=stats.sem(x))

low, high = mean_ci(minutes)
print(f"95% CI for the mean: {low:.1f} to {high:.1f} min")
95% CI for the mean: 33.5 to 46.8 min

So from these 30 people, a population mean anywhere from about 33 to 47 minutes fits the data. This is also where the most common misunderstanding comes in. A 95% confidence interval doesn’t mean there’s a 95% chance that the true mean is inside this particular interval. As the NIST handbook puts it, a given interval either contains the true mean or it doesn’t. The 95% describes the method: if you drew many samples and built an interval from each, in the long run about 95% of them would contain the true mean. You normally can’t check that, but here we can, because we know the whole population.

true_mean = minutes_all.mean()  # known only because we made the population
hits = 0
for _ in range(1000):
    lo, hi = mean_ci(rng.choice(minutes_all, size=30, replace=False))
    hits += lo <= true_mean <= hi
print(f"{hits} of 1000 intervals contain the true mean {true_mean:.1f}")
964 of 1000 intervals contain the true mean 39.0

964 out of 1,000 is close to 95%. The other 36 intervals missed, and from inside a single sample there’s no way to tell whether yours is one of them.

Hypothesis tests and p-values

A hypothesis test asks a slightly different question. You start from a claim, called the null hypothesis, and ask how surprising your data would be if that claim were true. Say one person claims the average user spends 45 minutes a day in the app, and another says 60. SciPy’s ttest_1samp tests the mean of one sample against a claimed value.

for claim in (45, 60):
    test = stats.ttest_1samp(minutes, popmean=claim)  # null hypothesis: mean == claim
    print(f"claim {claim} min: t = {test.statistic:.2f}, p = {test.pvalue:.2g}")
claim 45 min: t = -1.50, p = 0.14
claim 60 min: t = -6.14, p = 1.1e-06

The number to read is the p-value. In the informal definition from the American Statistical Association (ASA), it’s the probability, under a specified statistical model, that a summary of the data would be equal to or more extreme than what was observed. For the 60-minute claim, p is about one in a million, so data like ours would be very surprising if the claim were true. For 45 minutes, p is 0.14. With the common cutoff of 0.05, you’d call that not statistically significant. Yet we know the true mean is 39.0, so the 45-minute claim is wrong, and 30 people simply weren’t enough to show it. The confidence interval tells the same story, since it includes 45 but not 60.

On March 7, 2016, the ASA released a statement on p-values with six principles, many of which address exactly these misreadings. A p-value doesn’t measure the probability that the hypothesis is true, or the probability that the data came from chance alone, and it doesn’t measure the size of an effect or how important a result is. And conclusions shouldn’t rest only on whether a p-value crosses a threshold. The statement also says that a relatively large p-value is not evidence in favor of the null hypothesis, which is just what happened with the 45-minute claim.

Fitting a line to the data

Regression looks at how two variables move together, and here we’ll see how minutes in the app change with the number of notifications. The usual method, least squares, picks the line that makes the sum of the squared vertical distances from the points to the line as small as possible. SciPy’s linregress does it in one call.

fit = stats.linregress(notifs, minutes)
print(f"slope {fit.slope:.2f} min per notification, intercept {fit.intercept:.1f} min")
print(f"predicted at 20 notifications: {fit.intercept + fit.slope * 20:.1f} min")
slope 1.32 min per notification, intercept 11.8 min
predicted at 20 notifications: 38.2 min

The slope says that each extra notification goes with about 1.32 more minutes in the app, and the intercept of 11.8 is where the line sits at zero notifications. The last output is the line’s prediction for a user who gets 20 notifications a day. When I built the population, I used a slope of 1.2 and an intercept of 15. So the estimates are close but not exact, for the same reason the sample mean wasn’t exactly 39.0.

Still, the line only shows that the two numbers move together. It doesn’t show that notifications make people stay longer. I built the data that way here, but in real data, people who already use the app a lot might simply turn more notifications on. Finding the cause takes more, such as an experiment that randomly decides who gets notifications.

How statistics and machine learning differ

Machine learning uses many of the same tools, so the boundary can look blurry. Leo Breiman drew one in his 2001 paper Statistical Modeling: The Two Cultures. He wrote that analyzing data has two goals, prediction (what the response will be for future inputs) and information (how nature links the inputs to the response). He then described two cultures that pursue these goals differently.

Data modeling culture Algorithmic modeling culture
How the data arises Assumes a stochastic model, such as linear regression Treats it as complex and unknown
How a model is judged Goodness-of-fit tests and residuals Predictive accuracy
Examples Breiman gives Linear and logistic regression Decision trees, neural nets
Share he estimated 98% of statisticians 2% of statisticians, many in other fields

Breiman, a statistician at Berkeley, argued that his field leaned too heavily on data models. Meanwhile, he noted, algorithmic modeling had grown fast largely outside statistics, in a new community often called machine learning. Seen this way, the two mostly differ in the question they ask. Statistics more often asks what’s going on and how sure we can be, while machine learning more often asks how well we can predict data we haven’t seen yet.

Our regression line can play both roles. Reading the slope of 1.32 as minutes per notification is explaining, and plugging in 20 notifications to get 38.2 minutes is predicting. scikit-learn’s LinearRegression fits a linear model by minimizing the same sum of squares. That’s why learning AI starts with statistics. Learning from a sample, asking how well it carries over to new data, and saying how sure you are all begin here.

When statistics helps and when it misleads

Statistics works best when your question is about a larger group than you can observe, and when you need to say how sure you are. Polls, clinical trials, and A/B tests all share that shape. It works especially well when you can randomize who gets sampled or who gets which version, because the uncertainty calculations lean on that randomness.

It misleads when those assumptions break. If you survey only the users who opened the app today, the people who rarely use it drop out of your sample, and no formula can fix that afterward. Running many tests and reporting only the ones with small p-values makes those p-values hard to interpret, which is why the ASA statement asks for full reporting. On the other side, with a very large dataset even a tiny difference can produce a small p-value, so it helps to look at the size of the effect and its confidence interval too.

Where to start

If you’re new to this, I’d start by running the example above and changing one thing at a time. When I changed the sample from 30 users to 300, the 95% confidence interval narrowed to 35.6 to 39.4 minutes. If you’d rather not install anything, Python’s built-in statistics module has mean, stdev, and, since Python 3.10, linear_regression. For a book, OpenIntro Statistics is offered as a free PDF. An Introduction to Statistical Learning covers topics from regression to deep learning, and its Python edition came out in 2023. The next post in this series turns to machine learning, where a program learns rules like this line from data instead of having them written by hand. I ran these examples on October 27, 2026, with Python 3.13.12, NumPy 2.5.4, and SciPy 1.18.1.

AI tools helped with the research for this post.