Description
There is a very nice example of using GridSearchCV
with an unsupervised method, KernelDensity
, here. It has this code:
params = {'bandwidth': np.logspace(-1, 1, 20)}
grid = GridSearchCV(KernelDensity(), params)
grid.fit(data)
However, the documentation for GridSearchCV
here suggests that that code shouldn't work, because it assumes that the underlying method is supervised, and in particular is a classifier. It says things like:
"GridSearchCV implements a “fit” method and a “predict” method like any classifier except that the parameters of the classifier used to predict is optimized by cross-validation."
and
"scoring : string, callable or None, optional, default: None
A string (see model evaluation documentation) or a scorer callable object / function with signature scorer(estimator, X, y)."
(bold added in both cases).
In fact, GridSearchCV
correctly ends up using the KernelDensity.score
method. It is just that the documentation is confusing.