selectThreshold.m 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. function [bestEpsilon bestF1] = selectThreshold(yval, pval)
  2. %SELECTTHRESHOLD Find the best threshold (epsilon) to use for selecting
  3. %outliers
  4. % [bestEpsilon bestF1] = SELECTTHRESHOLD(yval, pval) finds the best
  5. % threshold to use for selecting outliers based on the results from a
  6. % validation set (pval) and the ground truth (yval).
  7. %
  8. bestEpsilon = 0;
  9. bestF1 = 0;
  10. F1 = 0;
  11. stepsize = (max(pval) - min(pval)) / 1000;
  12. for epsilon = min(pval):stepsize:max(pval)
  13. % ====================== YOUR CODE HERE ======================
  14. % Instructions: Compute the F1 score of choosing epsilon as the
  15. % threshold and place the value in F1. The code at the
  16. % end of the loop will compare the F1 score for this
  17. % choice of epsilon and set it to be the best epsilon if
  18. % it is better than the current choice of epsilon.
  19. %
  20. % Note: You can use predictions = (pval < epsilon) to get a binary vector
  21. % of 0's and 1's of the outlier predictions
  22. % =============================================================
  23. if F1 > bestF1
  24. bestF1 = F1;
  25. bestEpsilon = epsilon;
  26. end
  27. end
  28. end