Let's say I have the following custom loss function that I'm using in sci-kit learn. In this case I'm only scoring the observations where my model scores above 0.8.
def customLoss(y_true, y_pred):
a = pd.DataFrame({'Actuals':y_true, 'Preds': y_pred})
a = a.query('Preds > 0.8')
return(precision_score(a['Actuals'], a['Preds']))
param_grid = {'C': [0.001, 0.01, 0.1, 1, 10]}
scorer = make_scorer(mf.customLoss ,greater_is_better = True)
grid = GridSearchCV(LogisticRegression(class_weight = 'balanced'), param_grid = param_grid, scoring = scorer, cv = 5)
However, let's say I wanted to make the threshold (0.8) configurable. Obviously I would need to add a third argument to my loss function like this:
def customLoss(y_true, y_pred, threshold):
a = pd.DataFrame({'Actuals':y_true, 'Preds': y_pred})
a = a.query('Preds > @threshold')
return(precision_score(a['Actuals'], a['Preds']))
However, I'm a little confused on where in the make_scorer function I'd put this third argument?