How do you select the bandwidth for kernel density estimation in practice?

Quick Overview

Asks how to choose the bandwidth for kernel density estimation on a real dataset. Tests understanding of the smoothing bias-variance trade-off, the assumptions behind quick default rules, data-driven selection methods, and practical issues with multivariate or multimodal data.

How do you select the bandwidth for kernel density estimation in practice?

Role: Machine Learning Engineer

Category: Machine Learning

Difficulty: medium

Interview Round: Other

How do you select the bandwidth for kernel density estimation in practice? The bandwidth sets how wide each kernel is, so it controls how smooth the estimated density looks. Describe how you would choose it for a real dataset. ```hint Check the assumptions The quick default formulas are derived for one reference shape of data. Ask what happens to them when the true density has several peaks. ``` ```hint What to optimize If you want the data to choose the bandwidth, decide which score on held-out points you would maximize or minimize. ``` ### What a Strong Answer Covers - What the bandwidth trades off: a spiky, high-variance estimate when it is too small, and an oversmoothed one that hides structure when it is too large. - At least one closed-form rule of thumb and the assumption it rests on. - A data-driven method (plug-in or cross-validation) and the objective it optimizes. - Practical issues: feature scaling or a bandwidth matrix in several dimensions, the search grid, and adaptive bandwidths when density varies a lot. - How the downstream use of the density can change which bandwidth is best. ### Follow-up Questions - How fast should the optimal bandwidth shrink as $n$ grows, and how does that rate change with the dimension $d$? - Leave-one-out likelihood cross-validation can pick a degenerate bandwidth on some datasets. When does that happen? - If the KDE is used for anomaly detection and you have a few labeled anomalies, how would you choose the bandwidth? - How much does the choice of kernel matter compared with the choice of bandwidth?

Overview: Asks how to choose the bandwidth for kernel density estimation on a real dataset. Tests understanding of the smoothing bias-variance trade-off, the assumptions behind quick default rules, data-driven selection methods, and practical issues with multivariate or multimodal data.

Nov 24, 2026
mediumMachine Learning EngineerOtherMachine Learning
0
0

How do you select the bandwidth for kernel density estimation in practice?

The bandwidth sets how wide each kernel is, so it controls how smooth the estimated density looks. Describe how you would choose it for a real dataset.

What a Strong Answer Covers Guidance

  • What the bandwidth trades off: a spiky, high-variance estimate when it is too small, and an oversmoothed one that hides structure when it is too large.
  • At least one closed-form rule of thumb and the assumption it rests on.
  • A data-driven method (plug-in or cross-validation) and the objective it optimizes.
  • Practical issues: feature scaling or a bandwidth matrix in several dimensions, the search grid, and adaptive bandwidths when density varies a lot.
  • How the downstream use of the density can change which bandwidth is best.

Follow-up Questions Guidance

  • How fast should the optimal bandwidth shrink as nn grows, and how does that rate change with the dimension dd ?
  • Leave-one-out likelihood cross-validation can pick a degenerate bandwidth on some datasets. When does that happen?
  • If the KDE is used for anomaly detection and you have a few labeled anomalies, how would you choose the bandwidth?
  • How much does the choice of kernel matter compared with the choice of bandwidth?