我写了一个 KNN 插补实现,我希望 StratifiedKFold 来检查使用什么 K 和什么距离矩阵。我收到一个错误:它似乎没有将我的估算器识别为回归器(“评分”函数用于回归)。
我的代码:
skf = StratifiedKFold(n_splits=10, shuffle=False, random_state=12)
NN = KnnImputation() # my own function
gridSearchNN = GridSearchCV(NN, param_grid=params, scoring='mean_squared_error', n_jobs=numIter,
cv=skf.split(xTrain, yTrain), verbose=verbose)
gridSearchNN.fit(xTrain, yTrain)
错误:
File "........\dataImputation.py", line 63, in knnImputationMethod
gridSearchNN.fit(xTrain, yTrain)
File "C:\Users\...\Anaconda3\lib\site-packages\sklearn\model_selection\_search.py", line 651, in fit
cv = check_cv(self.cv, y, classifier=is_classifier(estimator))
File "C:\Users\....\Anaconda3\lib\site-packages\sklearn\model_selection\_split.py", line 2068, in check_cv
return _CVIterableWrapper(cv)
File "C:\Users\....\Anaconda3\lib\site-packages\sklearn\model_selection\_split.py", line 1966, in __init__
self.cv = list(cv)
File "C:\Users\...\Anaconda3\lib\site-packages\sklearn\model_selection\_split.py", line 331, in split
for train, test in super(_BaseKFold, self).split(X, y, groups):
File "C:\Users\...\Anaconda3\lib\site-packages\sklearn\model_selection\_split.py", line 100, in split
for test_index in self._iter_test_masks(X, y, groups):
File "C:\Users\...\Anaconda3\lib\site-packages\sklearn\model_selection\_split.py", line 681, in _iter_test_masks
test_folds = self._make_test_folds(X, y)
File "C:\Users\...\Anaconda3\lib\site-packages\sklearn\model_selection\_split.py", line 636, in _make_test_folds
allowed_target_types, type_of_target_y))
ValueError: Supported target types are: ('binary', 'multiclass'). Got 'continuous' instead.
在“GridSearchCV”过程中,我看到它进入“is_classifier”而不是“is_regressor”。
有任何想法吗?
米琪卡哇伊
相关分类