def get_bw_cv(x,params): grid = GridSearchCV(KernelDensity(), params,cv=2,n_jobs=1) grid.fit(x[:,None]) bw = grid.best_estimator_.bandwidth return bw