Guest User

Untitled

a guest
Apr 25th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 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 = object.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 minValue = meanValue - (1.5m * quartiles.IQR);
  17. decimal maxValue = meanValue + (1.5m * quartiles.IQR);
  18.  
  19. if ((objectFarthestFromMean.MyProperty < minValue) || (objectFarthestFromMean.MyProperty > maxValue))
  20. {
  21. objects.Remove(objectFarthestFromMean);
  22.  
  23. return RemoveOutliers(objects);
  24. }
  25.  
  26. // No outlier found, we're finished.
  27. return quartiles;
  28. }
  29.  
  30. decimal maxRange = (1.5m * quartiles.IQR);
  31.  
  32. if (Math.Abs(objectFarthestFromMean.MyProperty - meanValue) > maxRange)
  33. {
Add Comment
Please, Sign In to add comment