2
$\begingroup$

I am an experienced programmer, but new to Python and data science. I am following Aurelien Gerone's book and I don't understand one thing.

I create SGDClassifier and calculate its precision_recall_curve(). Then I am trying to find the lowest threshold to satisfy precision equal to 90%:

precisions, recalls, thresholds = precision_recall_curve(y_train, y_scores)
threshold_90_precision = thresholds[np.argmax(precisions >= 0.90)]

Why on earth I am searching for argmax if I need to find the minimum threshold value? If I try to use argmin I get the wrong value, with precision equal to 0.1.

As I understand this:

  • precisions >= 0.90 creates an array with precision scores only above or equal to 0.90,
  • argmax returns an index, at which I find the highest value in the given array (so this should be as far from 90% as possible, but it's not!),
  • then I choose a threshold with returned index.

What am I missing?

$\endgroup$

1 Answer 1

0
$\begingroup$

Okay, I solved this myself.

precisions >= 0.90 doesn't create an array with precision scores only above 90%, but it transforms this array to the array of Booleans, where precisions below 90% are turned to False and the others are True.

argmax, if there are multiple identical, maximum values (and True is max here) returns the first index of this occurrence.

I sometimes hate this book, why he just doesn't use method like "array.first_equals(True)"?

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.