-3

我试图使用 GridSearch 来迭代 MeanShift 算法的不同带宽值,它显示了这个错误;你们有谁知道我该如何解决这个问题?非常感谢!

# Using GridSearch for Algorithm Tuning
from sklearn.model_selection import GridSearchCV
meanshift=MeanShift()
C = range(48, 69) # For MeanShift bandwidth
param_grid = {"bandwidth": range(48, 69)}

mean_grid = GridSearchCV(estimator=meanshift, param_grid=param_grid, scoring=None)

mean_grid.fit(X)

这是我得到的错误:

TypeError: If no scoring is specified, the estimator passed should have a 'score' method. The estimator MeanShift(bandwidth=None, bin_seeding=False, cluster_all=True, min_bin_freq=1,
     n_jobs=1, seeds=None) does not.
4

2 回答 2

1

您不能很好地将 GridSearch 与无监督方法一起使用。

网格搜索的概念是在对保留的数据进行预测时选择那些得分最高的参数。但是由于大多数聚类算法无法对看不见的数据进行预测,所以这不起作用。

在无监督学习中选择“最佳”参数并不是那么简单。这就是为什么没有像 gridsearch 这样简单的自动化工具可用的原因。

于 2018-08-08T20:12:41.723 回答
0

这是因为MeanShift算法不包含score函数。在这种情况下,您必须在 中scoring指定GridSearchCV是一个完整的列表。

从以下文档GridSearchCV

参数:

估计器:估计器对象。

假设这实现了 scikit-learn 估计器接口。要么估计器需要提供score函数,要么scoring必须通过。

于 2018-08-08T10:27:21.640 回答