Abstract Given a sample of n observations from a density ƒ on R d , a natural estimator of ƒ( x) is formed by counting the number of points in some region R surrounding x and dividing this count by the d dimensional volume of R . This paper presents an asymptotically optimal choice for R . The optimal shape turns out to be an ellipsoid, with shape depending on x. An extension of the idea that uses a kernel function to put greater weight on points nearer x is given. Among nonnegative kernels, the familiar Bartlett-Epanechnikov kernel used with an ellipsoidal region is optimal. When using higher order kernels, the optimal region shapes are related to L p balls for even positive integers p.