The Python Oracle

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

Become part of the top 3% of the developers by applying to Toptal https://topt.al/25cXVn

--

Music by Eric Matyas
https://www.soundimage.org
Track title: Secret Catacombs

--

Chapters
00:00 Question
02:50 Accepted answer (Score 0)
03:09 Thank you

--

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

Question links:
[image]: https://i.stack.imgur.com/uFP38.jpg
[image]: https://i.stack.imgur.com/3pQC8.jpg
[image]: https://i.stack.imgur.com/Qq3D0.jpg

--

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