Cut the range into k bins with counts Nj. The counts are nearly Poisson with mean n f(tj)×(bin width), and the square root stabilises their variance: Yj = √(Nj + 1/4)/√(n×width) satisfies Yj ≈ √f(tj) + σεj with a known σ. So any regression smoother applies: here local linear regression with a Gaussian kernel, a tube-formula band for √f̄, and squaring back. Because σ is known, the bandwidth can be chosen by an unbiased risk estimate (Cp) as well as by leave-one-out cross-validation.
Range [−3, 3]; points outside go into the end bins. The bandwidth grid runs from half a bin width to 40% of the range (60 values, log-spaced). The estimate is r̂+2/∫r̂+2; the band is (r̂ ± cσ‖ℓ(x)‖)+2 divided by the same constant, with c from the tube formula. Cp(h) = RSS/k − σ2 + 2σ2ν/k; the leave-one-out curve is shown minus σ2 so the two are on the same scale. ISE over [−3, 3].
code/ch06_density_estimation.py (root_bin, ll_weights, tube_kappa0, density_by_regression).