Density Plot
A density plot is a smooth picture of how values in a dataset are spread out. If a histogram feels like “bars in bins,” a density plot feels like a continuous curve showing where the data tends to cluster.
What it shows
A density plot visualizes an estimate of the data’s probability density function: higher parts of the curve mean values are more common, lower parts mean they’re rarer. The y-axis is not “counts” (like a histogram); it’s density, scaled so that the area under the curve equals 1. That scaling makes it easy to compare distributions even when groups have different sample sizes.
How it’s built (kernel density estimation)
Most density plots use kernel density estimation (KDE). Think of placing a small, smooth “bump” (often a Gaussian) on each data point and adding them up. The key knob is the bandwidth (smoothing level):
- Too small: the curve gets wiggly and overreacts to noise.
- Too large: the curve gets overly smooth and can hide real structure (like two peaks).
Practical examples
Density plots are handy when you want to compare shapes:
- House prices: see whether prices are right-skewed and whether there are multiple “price tiers.”
- Exam scores: compare two classes; a second peak might suggest two skill groups.
- Medical measurements (e.g., blood pressure): check if a treatment group shifts the distribution.
Why it matters in AI/ML
In ML workflows, density plots help with EDA: spotting skew, multimodality, and outliers that affect preprocessing (log transforms, robust scaling) and model choice. They’re also used to detect dataset shift by comparing feature distributions between training and production data. You’ll commonly see KDE-based density plots in seaborn (Python) and ggplot2 (R).
Density Plot is a smooth curve that visualizes the estimated probability density of a continuous variable, typically using kernel density estimation. It shows where values concentrate, revealing distribution shape, skewness, and multimodality more clearly than a histogram when binning is sensitive. In AI/ML, it helps diagnose feature distributions, detect outliers, and compare train vs. test shift. Example: overlay density plots of a feature by class to assess separability.
Imagine you’re looking at a busy highway from above and you draw a smooth “traffic curve” showing where cars are most crowded. A density plot does something similar for data: it draws a smooth curve showing where values are most common and where they’re rare.
On the horizontal axis are the possible values (like ages or prices). The higher the curve at a point, the more data points are packed around that value. In statistics and machine learning, density plots help you quickly see the shape of your data—like whether it has one main peak, multiple peaks, or long tails—without the blocky look of a histogram.