liveBook · Manning

Standard deviation

As explained in Classic Computer Science Problems in Swift: Essential techniques for practicing programmers

Standard deviation is the square root of variance and measures the typical magnitude of deviations from the mean.

Standard deviation is the square root of variance. It measures the typical magnitude of values’ deviations from their mean and provides a statistical primitive for working with arrays of Double values. section 6.1

The calculation builds incrementally: sum supports mean, mean supports variance, and variance supports standard deviation. For an array, variance averages the squared differences from the mean, then std applies sqrt(). section 6.1

A small Swift calculation

For [600, 470, 170, 430, 300], the calculated variance is 21704 and the standard deviation is 147. The same primitive supports z-scores through (value − mean) / standard deviation. section 6.1

In k-means, standard deviation normalizes each dimension through z-scores so dimensions with larger numerical differences do not dominate distance-based clustering. section 6.2

How Classic Computer Science Problems in Swift: Essential techniques for practicing programmers covers it

How deep it goes
Implements the formula in Swift and demonstrates composition with variance, but defers elementary statistical theory.
Examples
Uses a five-value Double array producing variance 21704 and standard deviation 147.
What it assumes
Assumes rudimentary knowledge of mean and standard deviation while building the implementation from sum and mean.
What you can do after
Apply it via Swift Array extensions to calculate standard deviation and generate normalized z-scores.
How it connects
Connects standard deviation to mean, variance, z-scores, normalization, and k-means clustering.

Also explained in

Compare how 15 books explain standard deviation →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Classic Computer Science Problems in Swift: Essential techniques for practicing programmers. The section links point to the parts of the book it draws on.