Histograms and kernel density estimates
10 questions on nonparametric density estimation, bin width, the curse of dimensionality, kernel density estimates and the smoothing parameter.
- 10 questions
- Stopwatch
- Instant feedback
Sample questions
Play now ↑Answers stay hidden. Start the quiz to play them.
Sample 1
A histogram divides each of 3 variables into 20 bins. How many bins does it have in total?
- 60
- 8,000
- 400
Sample 2
In a kernel density estimate, what does the width of the bump control?
- The amount of smoothing: too small gives noise, too large washes out structure
- The number of data points used
- The height of the highest peak only
How it works
- One question per screen. An answer is final once sent.
- You see right away whether you were right, with a short explanation.
- The stopwatch runs: on equal scores, the faster player ranks first.
- Only your best attempt counts, so replaying is never risky.
About this quiz
A histogram is probably the first chart anyone draws to understand a set of numbers, and it is also a statistical model: an estimate of the probability density that the numbers came from. Unlike a Gaussian, it doesn't assume the shape in advance, which is why it is called nonparametric. That freedom comes with a catch that every analyst has met. Change the width of the bins and the picture changes dramatically, sometimes hiding real structure and sometimes inventing structure that isn't there. The same trade-off governs a smoother cousin, the kernel density estimate, and it turns out to be the same trade-off as in choosing how complicated any model should be.
This quiz teaches those ideas through concrete situations. It asks how a histogram turns counts into a proper density, what narrow and wide bins do to a data set with two clumps, and what practical advantages and disadvantages the method has. Then it moves to the point where histograms break down for good: when there are many variables instead of one or two. You will see why the number of bins explodes, and what that implies for the amount of data you would need.
The second part introduces the kernel density estimate. Instead of counting points in boxes, it places a small smooth bump on every data point and adds up the bumps. The width of the bump plays the role of the bin width, and you will see how it affects the result. You will also see what this method costs: it needs no training in the usual sense, but it has to keep the entire data set and consult all of it every time the density is evaluated.
Typical mistakes are to treat the default bin width of a plotting library as the truth, to assume that smoother always means better, and to forget that methods which look harmless in one dimension become hopeless in twenty. Another is to confuse the effort of fitting a model with the effort of using it. A good habit that follows from this quiz is to try several bin widths, or several kernel widths, before believing any single picture of a distribution. If a feature of the plot disappears when the width changes slightly, it is probably noise, and if it persists across widths, it is more likely to be real.
The quiz suits analysts, students and engineers who use histograms daily and want to understand what they are really estimating. No calculus is needed. There are 10 questions, each explained straight after you answer, and the quiz takes about four minutes.
Questions and answers
›How long does the quiz take?
About 3 to 4 minutes for 10 questions, at roughly 20 seconds each. An explanation appears after every answer.
›Do I need to have drawn a histogram before?
It helps, but isn't required. The questions describe what a histogram is, so you can answer them from the picture alone. If you have ever adjusted the number of bars in a chart, you already know the central problem.
›What does nonparametric mean?
A nonparametric method makes few assumptions about the shape of the distribution. Its form is determined largely by the data, so it grows more detailed as the data set grows. This contrasts with a parametric model, such as a Gaussian, which is governed by a fixed small number of parameters. Nonparametric methods trade a fixed, compact model for flexibility, and the price is that they must keep the data they were built from.
›How does a histogram estimate a probability density?
It divides the range into bins, counts the observations in each, and divides each count by the total number of observations and by the width of the bin. That makes the estimate a density, which is constant within each bin and integrates to one, not just a plot of raw counts.
›How do I choose the bin width?
There is no universal answer. The best width lies somewhere in between two failure modes, one of which creates structure and the other of which hides it. In practice, it is chosen by looking at the result, by rules of thumb, or by checking how well each candidate predicts data held back from the fit. A useful trick is to draw the histogram with several widths and keep only the features that survive all of them, since a feature that shows up at just one width is probably noise.
›What is the curse of dimensionality for histograms?
If each variable is divided into the same number of bins, the total number of bins is that number raised to the power of the number of variables. It grows exponentially, so most bins would be empty unless the amount of data is astronomically large. Histograms are therefore useful mainly in one or two dimensions.
›What is a kernel density estimate?
It is an estimate obtained by placing a small smooth bump, the kernel, on every observation and adding the bumps together, with a suitable overall scaling. A bell-shaped bump is a common choice. The result is smooth, unlike a histogram, which has jumps at the edges of its bins.
›What is the main drawback of kernel methods?
They have to store the whole data set. Training costs nothing, because storing the data is all that is required, but evaluating the density means going through every stored point, so the cost grows in proportion to the size of the data. This makes them slow for very large data sets. For large data sets, approximate search structures can also speed up evaluation considerably.