Skewness
Long tails.
Many datasets aren't symmetric. Incomes have a long tail to the right, because a few people earn a lot. That's called right skew, or positive skew. Easy exams have a tail to the left, because most people score high. That's left skew.

- Not everything is symmetric
- Long right tail: positive skew
- Long left tail: negative skew
Measuring skew
Sci Pi's stats module has a skew function. Zero means symmetric. Positive means a long right tail, and negative means a long left tail. Run it. The heights are close to zero. Incomes are strongly positive. And the easy exam is negative.
import numpy as np
from scipy.stats import skew
rng = np.random.default_rng(0)
heights = rng.normal(170, 8, 5000)
income = rng.lognormal(10, 0.7, 5000)
easy_exam = 100 - rng.exponential(10, 5000)
print("heights:", skew(heights).round(2))
print("income: ", skew(income).round(2))
print("exam: ", skew(easy_exam).round(2))heights: 0.02 income: 2.48 exam: -1.96
Fixing skew
Strong skew can confuse some models, like linear regression. A common fix is to take the logarithm. A log squashes big values much more than small ones, so the long tail gets pulled in. That's why you'll often see log of income, or log of price, in machine learning.
| key | value |
|---|---|
| skew ≈ 0 | symmetric |
| skew > 0 | right tail, mean > median |
| skew < 0 | left tail, mean < median |
| Fix | np.log of the values |
Summary
Skewness measures lopsidedness. Positive skew has a right tail, and the log often fixes it. Next, z scores, and how unusual a value is.
Key takeaways- scipy.stats.skew
- Right tail: positive
- np.log pulls in tails