根据自己的指标训练GridSearchCV

时间:2020-06-10 10:00:44

标签: python metrics xgboost scoring gridsearchcv

指标:

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))

GridSearchCV

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关联?

0 个答案:

没有答案