Probability & Statistic in Machine Learning(II)
- Published time
There are many different measures of central tendency
- Mean
- Median
- Mode
Expected Value#
Discrete random variables
Weighted using the PMF:
Continuous random variables
Weighted using the PDF:
Variance#
Variance is the expected value of the square minus the square of the expected value:
If and are independent:
Standard Deviation#
Sum of Gaussians#
The sum of two Gaussian random variables is still Gaussian.
Skewness and Kurtosis#
Consider two examples:
In case 1, you buy a 1, and 1% of the time you win $99.
In case 2, you are an insurance company selling a 1, and 1% of the time you lose $99.
Checking the first two moments:
The expected return and variance are identical — so how do we tell them apart?
We can use , the third moment, to distinguish them:
The formal definition of skewness is:
Case 1 (the lottery ticket) has positive skew: a long right tail, since most outcomes are small losses punctuated by a rare large gain. Case 2 (the insurance policy) has negative skew: a long left tail, since most outcomes are small gains punctuated by a rare large loss. Unlike variance, which only measures spread, skewness captures asymmetry — which direction the rare extreme outcome lies in.
This is the same pattern we'll see below with kurtosis: skewness (the 3rd moment) reveals the direction of tail risk, while kurtosis (the 4th moment) reveals its magnitude, and both can be invisible if you only look at mean and variance.
Here's another example to illustrate kurtosis:
Case 1
- 0.5 probability of winning $1
- 0.5 probability of losing $1
Case 2
- 100/202 probability of winning 10 cents
- 100/202 probability of losing 10 cents
- 1/202 probability of winning $10
- 1/202 probability of losing $10
Both cases have by symmetry. Checking the variance:
So a first- and second-moment view (mean and variance) says these two bets are essentially identical. But they feel very different: Case 1 is a steady coin flip, while Case 2 is "almost always a tiny, boring outcome, but with a rare catastrophic tail" — much like an insurance payout or a market crash. This is exactly what kurtosis is designed to capture.
The formal definition of kurtosis is the fourth standardized moment:
Because the deviations are raised to the 4th power, kurtosis is very sensitive to rare, large values (outliers) and much less sensitive to the frequent, small ones near the mean. In Case 2, the rare outcome dominates even though it barely affects the variance, so Case 2 has much higher kurtosis than Case 1.
This is why kurtosis matters: two distributions can share the same mean and variance, yet the fourth moment reveals a difference in tail risk — how likely extreme, low-probability events are. A distribution with higher kurtosis than the Gaussian is called leptokurtic ("fat-tailed"), and one with lower kurtosis is platykurtic ("thin-tailed"). In finance and ML, relying on variance alone can seriously understate the risk of rare but extreme events.
Quantiles and Box-Plots#
A quantile is a value below which a given proportion of the data falls — for example, the median is the 50th percentile (the 0.5-quantile).
The box plot below visualizes the quartiles, median, and outliers of a distribution:
Kernel Density Estimation: Approximate the PDF based on the data#
A histogram approximates a distribution's shape, but it's sensitive to bin width and bin placement, and it produces a blocky, discontinuous estimate. Kernel Density Estimation (KDE) is a non-parametric way to estimate a smooth PDF directly from samples, without assuming a parametric family (like Gaussian) up front.
The idea: place a small "bump" (the kernel) centered at each data point, then sum all the bumps and normalize:
where are the observed samples, is the kernel function (often a standard Gaussian), and is the bandwidth.
The bandwidth controls the smoothness of the estimate, and is the key bias-variance tradeoff in KDE:
- Too small : each bump is narrow, so the estimate is spiky and overfits the noise in the sample (high variance, low bias).
- Too large : the bumps are wide and overlap heavily, oversmoothing the estimate and washing out real structure like multiple modes (high bias, low variance).
In practice, is tuned via cross-validation or a plug-in rule (e.g. Silverman's rule of thumb), analogous to choosing bin width for a histogram — except KDE's output is a smooth, continuous curve rather than discrete bars.
Violin Plots#
Violin plots combine a KDE with a box plot to show both the distribution's shape and its summary statistics.
QQ Plots#
A QQ (quantile-quantile) plot compares the quantiles of a sample against the quantiles of a theoretical distribution (e.g. Gaussian) — points falling along the diagonal line indicate the sample follows that distribution.
Marginal and Conditional Distribution#
Marginal Distribution
Discrete case:
Continuous case:
Conditional Distribution
Discrete case:
Continuous case:
Covariance & Covariance Matrix#
If independent:
For a random vector, the covariance matrix collects the pairwise covariances between components:
Correlation Coefficient#
Looking at covariance alone can be misleading about the strength of a relationship, since it isn't scale-invariant. The correlation coefficient normalizes by the standard deviations:
Multivariate Gaussian Distribution#
Real-world data is often generated by multiple correlated variables jointly, which is where the multivariate Gaussian distribution comes in:
