Ten statistics essentials for data scientists

Machine learning models, dashboards and A/B tests all stand on a few statistical ideas. Some describe the data in front of you: where its centre is and how far it spreads. Others describe relationships between variables. And some answer the hardest question in data work: how much can a sample tell about everything you did not measure? Here are the ten concepts that come up again and again, with their formulas and what they are used for.

The bars of a histogram under a bell curve, with a dashed line at the mean and an arrow showing one standard deviation
The bars of a histogram under a bell curve, with a dashed line at the mean and an arrow showing one standard deviation

Mean: the balance point

The arithmetic mean adds all values and divides by how many there are:

\[\bar{x} = \frac{x_{1} + x_{2} + \dots + x_{n}}{n}\,.\]

Put the values on a number line as weights and the mean is the point where the line balances. It uses every value, which makes it efficient for symmetric data, but also sensitive: one billionaire in a room moves the average income enormously. Data scientists use the mean for averages such as revenue per user, to centre features before scaling them, and to fill in missing values of symmetric variables.

Гістограма з дзвоноподібною кривою, діаграма розмаху, діаграма розсіювання з лінією тренду та кругова діаграма
Гістограма з дзвоноподібною кривою, діаграма розмаху, діаграма розсіювання з лінією тренду та кругова діаграма

Median: the middle value

Sort the values and take the one in the middle, at position \((n + 1) / 2\); with an even number of values, take the mean of the two middle ones. Half the data lie below the median and half above. Because it depends only on the order of the values, an outlier hardly moves it. In skewed data, such as incomes, house prices or the time a web page takes to load, the mean lies in the long tail and the median is the better picture of a typical case; response times are often reported as the 50th percentile, p50.

Mode: the most frequent value

The mode is the value that occurs most often, or for continuous data the class of a histogram with the most values. A dataset can have two modes (bimodal) or more, which often means two groups are mixed together, and when every value occurs once there is no mode. It is the only average that works for categories: the most common browser, product or error message. It is also the usual way to fill in missing categorical values.

Variance: the average square

The variance measures spread:

\[s^{2} = \frac{\sum (x_{i} - \bar{x})^{2}}{n - 1}\,.\]

Each deviation from the mean is squared, so negative and positive deviations do not cancel, and large deviations count heavily. Geometrically, draw a square on each deviation: the variance is their average area. The sample variance divides by \(n - 1\) rather than n because the deviations are measured from the sample's own mean, which fits the sample better than the true mean would; this correction, named after Friedrich Bessel, makes it unbiased. Variance is the language of risk and volatility, of ANOVA and principal component analysis, and of the bias–variance trade-off in machine learning.

Standard deviation: spread in the data's units

The standard deviation is the square root of the variance, \(s = \sqrt{s^{2}}\), and so is measured in the data's own units: points, centimetres, euros. For data shaped like a bell curve about 68 % of the values lie within one standard deviation of the mean, 95 % within two and 99.7 % within three (the empirical rule). That makes it the yardstick for z-scores, \(z = (x - \bar{x}) / s\), which put features on one scale and flag values more than three standard deviations out as possible outliers.

Probability: a number between 0 and 1

A probability says how likely an event is, from 0 for impossible to 1 for certain. With equally likely outcomes it is the number of favourable outcomes divided by all outcomes. For a continuous variable it is an area under a density curve: under a normal model with mean \(\bar{x}\) and standard deviation s,

\[P (a \le X \le b) = \Phi (z_{2}) - \Phi (z_{1})\]

with \(z_{1} = (a - \bar{x}) / s\) and \(z_{2} = (b - \bar{x}) / s\), where Φ is the standard normal distribution function. Classifiers output probabilities of churn, fraud or a click, and decisions follow from thresholds and expected values.

Correlation: moving together

Pearson's correlation coefficient r measures how closely two variables follow a straight line, from −1 (a perfect falling line) through 0 (no linear relation) to 1 (a perfect rising line). It adds up the products of the deviations, \((x_{i} - \bar{x})\)(yᵢ − ȳ), which are positive when both values are above or both below their means, and divides by the spreads so the units drop out. A correlation does not prove that one variable causes the other: both may follow a third, and r misses relations that are strong but curved. Data scientists use it to explore data, to choose features and to spot multicollinearity before fitting a regression.

Hypothesis testing: real effect or chance?

A test starts from the null hypothesis \(H_{0}\) that there is no effect, for example that a new web page converts no better than the old one. It computes a test statistic, here Welch's t = (x̄₂ \(- \bar{x}\)₁) / \(\sqrt{s_{1}^{2} / n_{1} + s_{2}^{2} / n_{2}}\), and the p-value: the chance of a result at least this extreme if \(H_{0}\) were true. If p is below the significance level α chosen in advance, usually 0.05, \(H_{0}\) is rejected. Then about one in twenty tests of a true \(H_{0}\) still rejects it (a type I error), and a real but small effect is often missed in a small sample (a type II error), which is why A/B tests are planned with a sample size large enough to find the effect that matters.

Confidence interval: a range for the truth

A single estimate such as a sample mean hides its uncertainty. A confidence interval \(\bar{x} \pm t\)* · \(s / \sqrt{n}\) gives a range instead, where t* comes from Student's t distribution with \(n - 1\) degrees of freedom (2.045 for 95 % and \(n = 30\)). The 95 % describes the method: of many intervals from repeated samples, about 95 % contain the true mean. The margin of error shrinks with \(\sqrt{n}\), so halving it takes four times as much data, which is how surveys and experiments choose their sample size.

Linear regression: the best straight line

Simple linear regression predicts y from x with the line ŷ = \(b_{0} + b_{1} x\) that makes the sum of squared residuals, the vertical distances from the points to the line, as small as possible. The least-squares solution is

\[b_{1} = \sum (x_{i} - \bar{x})\]

(yᵢ − ȳ) / \(\sum (x_{i} - \bar{x})^{2}\) and \(b_{0}\) = ȳ \(- b_{1} \bar{x}\), so the line always passes through the point of means. The slope says how much y changes per unit of x, and \(R^{2}\), here the square of r, the share of the variation in y that the line explains. Regression is used for forecasts, for measuring effects, and as the starting point of many machine learning methods.

How the app draws the ten concepts

Every concept is drawn on the same kind of sample: exam scores, heights, house prices, delivery times or shoe sizes, drawn at random from a realistic model, with a partner variable for correlation and regression. The mean sits on a fulcrum under a dot plot, the median lights the middle bars of the sorted values, the mode the tallest bar of a histogram, the variance draws a square on every deviation and their average square, the standard deviation shades bands of one, two and three s under the bell curve, and probability shades the area between a and b. Correlation splits the scatter plot into quadrants, the test compares a control and a treatment group and shows the t distribution with α and p, and the confidence interval draws many repeated samples. A card beside the chart gives the definition, the formula worked out with the sample's numbers and three uses.

Поширені запитання

What is the difference between descriptive and inferential statistics?

Descriptive statistics summarise the data you have: the mean, median, mode, variance, standard deviation and correlation of this sample. Inferential statistics use a sample to say something about the population it came from, with an honest statement of the uncertainty: confidence intervals, hypothesis tests and the coefficients of a regression model.

Is a p-value of 0.05 the probability that the result is due to chance?

No. The p-value is the probability of data at least as extreme as yours if the null hypothesis were true, not the probability that the null hypothesis is true. A p-value of 0.03 means such a difference would be rare without an effect, not that there is a 97 % chance the effect is real. That depends also on how plausible the effect was before the test and on how many tests were run.

Why do statistics change when I draw a new sample?

Because each sample contains different individuals. This sampling variation is exactly what standard errors, confidence intervals and tests measure. Larger samples vary less: the standard error of the mean is s / √n, so a sample four times as large gives a mean that varies half as much.

How much does one outlier change the mean, the median and the standard deviation?

The mean moves by the outlier's distance from the mean divided by n + 1, so in a sample of 30 a value 100 points too high adds about 3.2 points. The median moves by at most half a step between neighbouring values. The variance and standard deviation react most, because the outlier's deviation is squared. Robust statistics such as the median and the interquartile range are used where outliers are expected.

Готові спробувати?

Відкрийте PictorX у браузері — без встановлення і без кредитної картки.

Open the statistics essentials app