Last updated
Standard Deviation & Variance
Definition: Standard deviation measures how spread out the numbers are. A low value means the data is clustered near the mean; a high value means it is widely scattered.
Example — compare two datasets
import statistics as st
tight = [98, 100, 101, 99, 102]
wide = [20, 100, 60, 180, 40]
print("Tight spread:", round(st.pstdev(tight), 2))
print("Wide spread: ", round(st.pstdev(wide), 2))
Both lists can have a similar mean, but very different spreads — and the spread often matters more than the average.
Variance
Variance is simply the standard deviation squared. They measure the same idea:
import statistics as st
data = [10, 12, 14, 16, 18]
print("Std deviation:", round(st.pstdev(data), 2))
print("Variance: ", round(st.pvariance(data), 2))
💡 Why ML cares: features with very different spreads can confuse a model, which is why data is often "scaled" before training.
Try it Yourself
Output
Ad · responsive