You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

selectThreshold.m 1.5 kB

8 years ago
12345678910111213141516171819202122232425262728293031323334353637383940
  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. predictions = (pval < epsilon);
  23. tp = sum((predictions == 1) & (yval == 1));
  24. fp = sum((predictions == 1) & (yval == 0));
  25. fn = sum((predictions == 0) & (yval == 1));
  26. tn = sum((predictions == 0) & (yval == 0));
  27. F1 = (2 * (tp / (tp + fp)) * (tp / (tp + fn))) / ((tp / (tp + fp)) + (tp / (tp + fn)));
  28. % =============================================================
  29. if F1 > bestF1
  30. bestF1 = F1;
  31. bestEpsilon = epsilon;
  32. end
  33. end
  34. end

机器学习

Contributors (1)