When estimating a mean regression function and its derivatives, locally weighted least squares regression has proven to be a very attractive technique. The present paper focuses on the important issue of how to select the smoothing parameter or bandwidth. In the case of estimating curves with a complicated structure, a variable bandwidth is desirable. Furthermore, the bandwidth should be indicated by the data themselves. Recent developments in nonparametric smoothing techniques inspired us to propose such a datadriven bandwidth selection procedure, which can be used to select both constant and variable bandwidths. The idea is based on a residual squares criterion along with a good approximation of the bias and variance of the estimator. The procedure can be applied to select bandwidths not only for estimating the regression curve but also for estimating its derivatives. The resulting estimation