devnotes.

Skewness and Kurtosis

Introduction

The mean and standard deviation tell us where the data is centred and how spread out it is, but they say nothing about the shape of the distribution. Two datasets can share the same mean and standard deviation yet look completely different: one symmetric, one heavily lopsided, one with many extreme values.

Skewness and kurtosis are two numbers that describe the shape:

  • Skewness measures asymmetry: does the distribution lean left or right?
  • Kurtosis measures tail weight: how prone is the data to extreme values (outliers)?

They belong to a family called moments of a distribution: the 1st moment is the mean, the 2nd is the variance, the 3rd (standardised) is skewness and the 4th (standardised) is kurtosis.

Skewness

Definition

The skewness of a dataset with mean x̄ and n values is the standardised third moment:

Skewness (g₁) = [ (1/n) Σ (xᵢ − x̄)³ ] / [ (1/n) Σ (xᵢ − x̄)² ]^(3/2)

Cubing the deviations keeps the sign, so values far above the mean push skewness positive and values far below push it negative.

Many software packages also offer a bias-corrected sample version (G₁) for small samples. For large n the two are nearly identical.

Types of skewness

SkewnessNameShapeMean vs median
≈ 0SymmetricBalanced, like the normal curvemean ≈ median
> 0Positively (right) skewedLong tail on the rightmean > median
< 0Negatively (left) skewedLong tail on the leftmean < median
Right-skewed:            Symmetric:             Left-skewed:
   █                        █                        █
   ██                      ███                      ██
   ████                   █████                   ████
   ████████▁▁▁          ███████▁▁▁▁            ▁▁▁████████
   mode<median<mean       all equal           mean<median<mode

Interpreting the value (rule of thumb)

Absolute skewnessInterpretation
0 to 0.5Approximately symmetric
0.5 to 1Moderately skewed
Greater than 1Highly skewed

Simple skewness measures (Pearson)

When you only have summary statistics:

Pearson's first coefficient:   (mean − mode) / standard deviation
Pearson's second coefficient:  3 × (mean − median) / standard deviation

Real-world examples

  • Right-skewed: income, house prices, city populations, waiting times, website session lengths. A few very large values pull the mean up.
  • Left-skewed: age at retirement, scores on an easy exam (most students score high), lifespans in a developed country.

Kurtosis

Definition

Kurtosis is the standardised fourth moment:

Kurtosis = [ (1/n) Σ (xᵢ − x̄)⁴ ] / [ (1/n) Σ (xᵢ − x̄)² ]²

Raising deviations to the fourth power makes extreme values dominate the sum, so kurtosis is mostly about the tails.

The normal distribution has kurtosis = 3. To make comparisons easier we use excess kurtosis:

Excess kurtosis = Kurtosis − 3        (normal distribution → 0)

Types of kurtosis

Excess kurtosisNameTailsExample
≈ 0MesokurticLike the normal distributionNormal
> 0LeptokurticHeavy tails, more outliersStock returns, Laplace, Student's t
< 0PlatykurticLight tails, fewer outliersUniform (excess = −1.2)

Common myth: kurtosis is not really about the "peakedness" of the curve. It is about the weight of the tails. A distribution with high kurtosis produces more extreme outliers.

Library note: scipy.stats.kurtosis and pandas.Series.kurt() both return excess kurtosis by default. Pass fisher=False in SciPy to get the plain kurtosis (normal = 3).

Checking normality

Many methods assume roughly normal data, or at least normal residuals. To check:

  • Histogram / KDE plot: look at the shape.
  • Q-Q plot: points follow a straight line if the data is normal; curved ends indicate heavy tails, an S-shape indicates skew.
  • Skewness and excess kurtosis near 0.
  • Formal tests: Shapiro-Wilk, D'Agostino's K² test (built on skewness and kurtosis), Jarque-Bera.

Fixing skewed data

Skewed features can hurt linear models, distance-based models and neural networks. Common transformations:

SkewTransform
Moderate right skewSquare root
Strong right skewLog (log1p handles zeros)
Right skew, wide rangeBox-Cox (positive values only) or Yeo-Johnson (any values)
Left skewReflect (max + 1 − x) then apply a right-skew transform, or square/cube

Tree-based models (random forests, gradient boosting) are largely insensitive to skewness because they only use the ordering of values.

Real-life applications

  • Finance: return distributions with negative skew and high kurtosis signal crash risk. A "normal" model badly underestimates it.
  • Insurance: claim sizes are right-skewed with heavy tails.
  • Quality control: skewness reveals whether a process drifts in one direction.
  • Healthcare: hospital length-of-stay and cost data are right-skewed.

Where it appears in machine learning

  • Feature engineering: decide whether to log-transform features such as price, income or counts.
  • Regression diagnostics: residuals should be roughly symmetric with light tails.
  • Outlier risk: heavy-tailed data lets a few extreme points dominate a squared-error loss.
  • Target transformation: predicting log(price) instead of price often improves models.

Python implementation

import numpy as np
import pandas as pd
from scipy import stats

rng = np.random.default_rng(42)
normal = rng.normal(0, 1, 100_000)
expo   = rng.exponential(1.0, 100_000)

print("Normal:      skew", round(stats.skew(normal), 2), " excess kurtosis", round(stats.kurtosis(normal), 2))
print("Exponential: skew", round(stats.skew(expo), 2),   " excess kurtosis", round(stats.kurtosis(expo), 2))
# Exponential theory: skew = 2, excess kurtosis = 6

# pandas versions
s = pd.Series(expo)
print(s.skew(), s.kurt())

# Transformations
from sklearn.preprocessing import PowerTransformer
x_log = np.log1p(expo)
pt = PowerTransformer(method="yeo-johnson")
x_yj = pt.fit_transform(expo.reshape(-1, 1))

print("Skew after log1p:", round(stats.skew(x_log), 2))
print("Skew after Yeo-Johnson:", round(stats.skew(x_yj.ravel()), 2))

Solved examples

Example 1: Pearson's second coefficient

A dataset has mean 50, median 45 and standard deviation 10. Describe its skewness.

Solution. Skewness = 3 × (50 − 45)/10 = 1.5. This is positive and greater than 1, so the data is highly right-skewed.

Example 2: Computing skewness and kurtosis by hand

Data: 1, 2, 3, 4, 10.

Solution.

  • Mean = 20/5 = 4. Deviations: −3, −2, −1, 0, 6.
  • Squares: 9, 4, 1, 0, 36, so m₂ = 50/5 = 10.
  • Cubes: −27, −8, −1, 0, 216, so m₃ = 180/5 = 36.
  • Fourth powers: 81, 16, 1, 0, 1296, so m₄ = 1394/5 = 278.8.

Skewness = m₃ / m₂^(3/2) = 36 / 31.62 ≈ 1.14 (right-skewed, because of the value 10).

Kurtosis = m₄ / m₂² = 278.8 / 100 = 2.79, so excess kurtosis ≈ −0.21 (close to normal in tail weight).

Example 3: Salary data

The mean salary in a company is 72,000 and the median is 55,000. What does this suggest?

Solution. Mean > median indicates right skew: a small number of very high salaries pull the mean up. The median is the better description of the "typical" employee.

Example 4: Classifying by excess kurtosis

Classify distributions with excess kurtosis of −1.2, 0 and +3.

Solution.

  • −1.2 (like a uniform distribution): platykurtic, light tails.
  • 0 (like the normal): mesokurtic.
  • +3 (like a Laplace distribution): leptokurtic, heavy tails and more outliers.

Example 5: Choosing a transformation

A feature "transaction amount" has skewness 3.2 and all values are positive. What should you do before fitting a linear model?

Solution. The feature is highly right-skewed, so apply a log transform (np.log1p) or Box-Cox, then recheck the skewness (it should move much closer to 0).

Common mistakes

  • Comparing kurtosis values from different libraries without checking whether they are "excess" or not.
  • Describing kurtosis as "peakedness".
  • Computing skewness on a tiny sample and trusting it (estimates are very noisy for small n).
  • Automatically transforming every feature. Only do it when it helps the model or meets an assumption.
  • Forgetting to apply the same fitted transformation to the test data.

Practice problems

  1. A dataset has mean 30, median 35 and standard deviation 5. Use Pearson's second coefficient. Is it left or right skewed?
  2. Data: 2, 4, 6. What is the skewness?
  3. A dataset has excess kurtosis 2.5. What is its (non-excess) kurtosis, and what type is it?
  4. A dataset has the values 1, 1, 1, 2, 10. Is the skewness positive or negative?
  5. Name two transformations for right-skewed positive data.
  6. What is the kurtosis and the excess kurtosis of a normal distribution?

Answers

  1. 3 × (30 − 35)/5 = −3, so strongly left-skewed
  2. The data is symmetric, so skewness = 0
  3. Kurtosis = 5.5; it is leptokurtic (heavy tails)
  4. Positive (the large value 10 creates a long right tail)
  5. For example log (log1p), square root, Box-Cox, Yeo-Johnson
  6. Kurtosis = 3; excess kurtosis = 0

Key takeaways

  • Skewness measures asymmetry: positive = right tail, negative = left tail.
  • Kurtosis measures tail heaviness. Excess kurtosis = kurtosis − 3; the normal distribution has 0.
  • Compare mean and median for a quick skew check.
  • Log, square-root and power transforms tame right-skewed features and can improve many models.
  • Always check which convention (excess or not) your library uses.

Further reading

Skewness and Kurtosis Explained with Python | DevNotes