tukeyized 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/tukeyized.rb +32 -2
- data/tukeyized.gemspec +4 -3
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 052e646b46d69e3a3abff1f6a208c29111c6f79bc2f41d29669c5ac4be89321e
|
4
|
+
data.tar.gz: d94e1a875960cdfff9ceafd8b232d878543ec11c41002c994485ceec44ff85c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 92bca8ec3eb6ef1895dd18b6397002cba65b1ed4fd2814fe54a3268e04cf72a80a7a9646cd836a021213324caedc4c7f2ae6e913cb185da998803274531adfbb
|
7
|
+
data.tar.gz: 292cb6ac821feb95fed8136b01330f03fa013b60964d98bb8e4be040ebdaabea959bf3b0d27747b16a14826c9eb68bdb9d61cd4307fab1bc1bc53e64f6fd8881
|
data/lib/tukeyized.rb
CHANGED
@@ -5,13 +5,43 @@
|
|
5
5
|
|
6
6
|
# Array.
|
7
7
|
#
|
8
|
+
# This class extends the standard Ruby Array with a method to remove
|
9
|
+
# extreme values using Tukey's method (also known as the Tukey fence
|
10
|
+
# for outlier detection). The method calculates the interquartile range
|
11
|
+
# and filters out values that fall outside 1.5 times the IQR from the
|
12
|
+
# first and third quartiles.
|
13
|
+
#
|
14
|
+
# For example:
|
15
|
+
#
|
16
|
+
# require 'tukeyized'
|
17
|
+
# [1, 6, 3, 8888, 3, 2, 8, -19292].tukeyized
|
18
|
+
# # => [1, 6, 3, 3, 2, 8]
|
19
|
+
#
|
8
20
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
9
21
|
# Copyright:: Copyright (c) 2025 Yegor Bugayenko
|
10
22
|
# License:: MIT
|
11
23
|
class Array
|
12
|
-
# Removes extreme values.
|
24
|
+
# Removes extreme values using Tukey's method.
|
25
|
+
#
|
26
|
+
# This method identifies and removes outliers from the array by calculating
|
27
|
+
# the first quartile (Q1), third quartile (Q3), and interquartile range (IQR).
|
28
|
+
# Values outside the range [Q1 - 1.5*IQR, Q3 + 1.5*IQR] are considered outliers
|
29
|
+
# and are excluded from the result.
|
30
|
+
#
|
31
|
+
# The original array is not modified; a new array is returned.
|
32
|
+
#
|
33
|
+
# For example:
|
34
|
+
#
|
35
|
+
# [1, 2, 3, 4, 5, 100].tukeyized
|
36
|
+
# # => [1, 2, 3, 4, 5]
|
37
|
+
#
|
38
|
+
# [10, 20, 30, 40, 50].tukeyized
|
39
|
+
# # => [10, 20, 30, 40, 50]
|
40
|
+
#
|
41
|
+
# [].tukeyized
|
42
|
+
# # => []
|
13
43
|
#
|
14
|
-
# @return [Array] New array
|
44
|
+
# @return [Array] New array without extreme values
|
15
45
|
def tukeyized
|
16
46
|
return [] if empty?
|
17
47
|
percentile = lambda do |a, x|
|
data/tukeyized.gemspec
CHANGED
@@ -9,11 +9,12 @@ Gem::Specification.new do |s|
|
|
9
9
|
s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
|
10
10
|
s.required_ruby_version = '>=3.2'
|
11
11
|
s.name = 'tukeyized'
|
12
|
-
s.version = '0.0
|
12
|
+
s.version = '0.1.0'
|
13
13
|
s.license = 'MIT'
|
14
|
-
s.summary = '
|
14
|
+
s.summary = 'Remove Array elements using Tukey\'s method'
|
15
15
|
s.description =
|
16
|
-
'
|
16
|
+
'This gem adds a simple tukeyized method to the Array class that ' \
|
17
|
+
'returns a copy of the array without extreme values using Tukey\'s method'
|
17
18
|
s.authors = ['Yegor Bugayenko']
|
18
19
|
s.email = 'yegor256@gmail.com'
|
19
20
|
s.homepage = 'https://github.com/yegor256/tukeyized'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tukeyized
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yegor Bugayenko
|
@@ -9,7 +9,8 @@ bindir: bin
|
|
9
9
|
cert_chain: []
|
10
10
|
date: 1980-01-02 00:00:00.000000000 Z
|
11
11
|
dependencies: []
|
12
|
-
description:
|
12
|
+
description: This gem adds a simple tukeyized method to the Array class that returns
|
13
|
+
a copy of the array without extreme values using Tukey's method
|
13
14
|
email: yegor256@gmail.com
|
14
15
|
executables: []
|
15
16
|
extensions: []
|
@@ -48,5 +49,5 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
48
49
|
requirements: []
|
49
50
|
rubygems_version: 3.6.9
|
50
51
|
specification_version: 4
|
51
|
-
summary:
|
52
|
+
summary: Remove Array elements using Tukey's method
|
52
53
|
test_files: []
|