Created
November 20, 2015 01:13
-
-
Save Eunoia/d72d4c43face15e13106 to your computer and use it in GitHub Desktop.
Uses DescriptiveStatistics to find outliers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def self.high_outliers(column) | |
values = pluck(column) | |
q1 = DescriptiveStatistics::Stats.new(select{|d| d.send(column)<values.median }.map{ |d| d.send(column)}).median | |
q3 = DescriptiveStatistics::Stats.new(select{|d| d.send(column)>values.median }.map{ |d| d.send(column)}).median | |
iqr = q3-q1 | |
select { |d| d.send(column)>(q3 + 1.5 * iqr) } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment