Guest User

Untitled

a guest
Apr 25th, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. public Quartiles RemoveOutliers(ICollection<MyObject> objects)
  2. {
  3. if (objects.Count == 0)
  4. {
  5. return new Quartiles();
  6. }
  7.  
  8. // Calculate Mean value of the set.
  9. decimal meanValue = objects.Average(o => o.MyProperty);
  10.  
  11. // Find the Object whose value is farthest from the Mean.
  12. MyObject objectFarthestFromMean = objects.OrderByDescending(o => Math.Abs(o.MyProperty - meanValue)).First();
  13. Quartiles quartiles = objects.Quartiles(o => o.MyProperty);
  14.  
  15. // Remove Object if its value is more than 1.5*IQR from the Mean.
  16. decimal maxRange = 1.5m * quartiles.IQR;
  17.  
  18. if (Math.Abs(objectFarthestFromMean.MyProperty - meanValue) > maxRange)
  19. {
  20. objects.Remove(objectFarthestFromMean);
  21.  
  22. return RemoveOutliers(objects);
  23. }
  24.  
  25. // No outlier found, we're finished.
  26. return quartiles;
  27. }
  28.  
  29. decimal maxRange = (1.5m * quartiles.IQR);
  30.  
  31. if (Math.Abs(objectFarthestFromMean.MyProperty - meanValue) > maxRange)
  32. {
Add Comment
Please, Sign In to add comment