The Python Oracle

Scikit-learn classifier with custom scorer dependent on a training feature

--------------------------------------------------
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
and get $2,000 discount on your first invoice
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Beneath the City Looping

--

Chapters
00:00 Scikit-Learn Classifier With Custom Scorer Dependent On A Training Feature
01:54 Accepted Answer Score 0
02:06 Thank you

--

Full question
https://stackoverflow.com/questions/4924...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python #machinelearning #scikitlearn #classification #gridsearch

#avk47



ACCEPTED ANSWER

Score 0


You can do something like this (note you have given no real code so this is barebones)

X = [...]
y = [...]

def custom_scorer_function(y, y_pred, **kwargs):
   a_feature = X[:,1]
   # now have y, y_pred and the feature you want

custom_scorer = make_scorer(custom_scorer_function, greater_is_better=True)
...