看起来您的标签数组的值为"no"和"yes",您应该将它们转换为二进制1-0数字表示,因为您的错误表明评分函数无法理解标签数组中0和1的位置.
在不修改标签数组的情况下解决此问题的其他方法:
from sklearn.metrics import f1_score from sklearn.metrics import make_scorer f1_scorer = make_scorer(f1_score, pos_label="yes") reg = grid_search.GridSearchCV(estimator=neigh,param_grid=parameters,scoring=f1_scorer)