Scikit-learn make_scorer custom metric problem for multiclass clasification
I was doing a churn analysis using:
randomcv = RandomizedSearchCV(estimator=clf,param_distributions = params_grid,
cv=kfoldcv,n_iter=100, n_jobs=-1, scoring='roc_auc')
and everything was fine, but then, I tried it with a custom scoring function this way:
def gain_fn(y_true, y_prob):
tp = np.where((y_prob = 0.02) (y_true==1), 40000, 0)
fp = np.where((y_prob = 0.02) (y_true==0), -1000, 0)
return np.sum([tp,fp])
scorer_fn = make_scorer(gain_fn, greater_is_better = True, needs_proba=True)
randomcv = RandomizedSearchCV(estimator=clf,param_distributions = params_grid,
cv=kfoldcv,n_iter=100, n_jobs=-1, scoring=scorer_fn)
but I need to make a calculation, inside of gain_fn
, with y_prob
of a specific class (it has 3 possible values). Any suggestions?
Topic scoring scikit-learn python
Category Data Science