Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public Quartiles RemoveOutliers(ICollection<MyObject> objects)
- {
- if (objects.Count == 0)
- {
- return new Quartiles();
- }
- // Calculate Mean value of the set.
- decimal meanValue = objects.Average(o => o.MyProperty);
- // Find the Object whose value is farthest from the Mean.
- MyObject objectFarthestFromMean = object.OrderByDescending(o => Math.Abs(o.MyProperty - meanValue)).First();
- Quartiles quartiles = objects.Quartiles(o => o.MyProperty);
- // Remove Object if its value is more than 1.5*IQR from the Mean.
- decimal minValue = meanValue - (1.5m * quartiles.IQR);
- decimal maxValue = meanValue + (1.5m * quartiles.IQR);
- if ((objectFarthestFromMean.MyProperty < minValue) || (objectFarthestFromMean.MyProperty > maxValue))
- {
- objects.Remove(objectFarthestFromMean);
- return RemoveOutliers(objects);
- }
- // No outlier found, we're finished.
- return quartiles;
- }
- decimal maxRange = (1.5m * quartiles.IQR);
- if (Math.Abs(objectFarthestFromMean.MyProperty - meanValue) > maxRange)
- {
Add Comment
Please, Sign In to add comment