data_mining 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/data_mining/dbscan.rb +14 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 974c994068ee3cf5b01c62f5b406f5ae327d17d3
|
4
|
+
data.tar.gz: e95b21a5a62291a3342b32b2b16db1ba31ae9e99
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e81c069008ec95bcc3598b29437890a497917b33e3a873dacbca64265f98681b5f1f8e2484c7fe893597d09837574a35fc846c049cd68c33e159d17c78b5abd2
|
7
|
+
data.tar.gz: b51412c6449a85a22ca5258d2731847abea52a498202bc12f6e4167c1ad28989f60e634c015e0f19409dde655b026a2dd20b5d3eb492f3b1ddbc9db83d9faeef
|
data/lib/data_mining/dbscan.rb
CHANGED
@@ -4,7 +4,7 @@ module DataMining
|
|
4
4
|
# Find clusters and outliers
|
5
5
|
#
|
6
6
|
# Example:
|
7
|
-
# >> input = [[:p1, 1], [:p2, 2], [:p3, 10]]
|
7
|
+
# >> input = [[:p1, [1,1]], [:p2, [2,1]], [:p3, [10,11]]]
|
8
8
|
# >> radius = 3
|
9
9
|
# >> min_points = 2
|
10
10
|
# >> dbscan = DataMining::DBScan.cluster(input, radius, min_points)
|
@@ -96,9 +96,21 @@ module DataMining
|
|
96
96
|
end
|
97
97
|
|
98
98
|
def neighbors?(p1, p2)
|
99
|
-
|
99
|
+
fail ArgumentError, 'Wrong point coordinates' unless valid_points?(p1, p2)
|
100
|
+
return true if p1 != p2 && euclidean_distance(p1, p2).abs <= @radius
|
100
101
|
false
|
101
102
|
end
|
103
|
+
|
104
|
+
def valid_points?(p1, p2)
|
105
|
+
return false if p1.value.length != p2.value.length
|
106
|
+
(p1.value + p2.value).all? { |x| x.is_a? Numeric }
|
107
|
+
end
|
108
|
+
|
109
|
+
def euclidean_distance(p1, p2)
|
110
|
+
p1 = p1.value
|
111
|
+
p2 = p2.value
|
112
|
+
Math.sqrt(p1.each_with_index.inject(0) { |sum, (v, i)| sum + ((v - p2[i])**2) })
|
113
|
+
end
|
102
114
|
end
|
103
115
|
end
|
104
116
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: data_mining
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Manuel Stuefer
|
@@ -19,7 +19,7 @@ files:
|
|
19
19
|
- lib/data_mining.rb
|
20
20
|
- lib/data_mining/dbscan.rb
|
21
21
|
- lib/data_mining/point.rb
|
22
|
-
homepage:
|
22
|
+
homepage: https://github.com/mstuefer/data_mining
|
23
23
|
licenses:
|
24
24
|
- MIT
|
25
25
|
metadata: {}
|