def my_score_func(y_true, y_pred):
global weights
return weights[(y_pred==1) & (y_true==1) & (weights>=0)].sum()
my_scorer = make_scorer(my_score_func, greater_is_better=True)
x = np.random.randint(0,2,size=(1000, 5))
y = np.random.randint(0,2,size=(1000, 1))
weights = np.random.randint(-100,100,size=(1000, 1))
XGB = xgboost.XGBClassifier()
param_grid = {'n_estimators': [20,30,50,80,100]}
XGBgs = GridSearchCV(XGB, param_grid, scoring = my_scorer, cv = 2)
XGBgs.fit(x, y)
ValueError:操作数不能与形状一起广播 (501,501)(1000,1)
但是使用标准指标“ f1”,“ roc_auc”,搜索有效
如何将此指标与GridSearchCV关联?