The Python Oracle

Setting a threshold in classifier output in Python

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: Digital Sunset Looping

--

Chapters
00:00 Question
01:11 Accepted answer (Score 2)
01:48 Thank you

--

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

--

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

--

Tags
#python #classification

#avk47



ACCEPTED ANSWER

Score 2


As far as I know, SVC itself does not allow thresholding of probabilities in the manner you want. You can do a second pass of indexing and get the accepted labels after you build labels_predicted and probabilities.

thresh = 0.9
accepted_probabilities_idx = probabilities.max(axis=1) > thresh
accepted_labels_predicted = labels_predicted[accepted_probabilities_idx]
accepted_new_data = pandas.DataFrame(new_data, index=accepted_probabilities_idx)

I am not sure what you want to do with data where ML-probability with low. This solution discards it completely.