kmeans 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/VERSION +1 -1
- data/doc/ChangeLog +5 -0
- data/kmeans.gemspec +5 -4
- data/lib/kmeans.rb +1 -1
- data/lib/kmeans/cluster.rb +21 -17
- data/lib/kmeans/dendrogram.rb +2 -0
- data/lib/kmeans/hcluster.rb +2 -0
- data/spec/lib/kmeans/cluster_spec.rb +55 -0
- data/spec/lib/kmeans/pair_spec.rb +8 -8
- data/spec/lib/kmeans/pearson_spec.rb +62 -62
- data/spec/lib/kmeans_spec.rb +1 -1
- metadata +13 -21
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4fbc7ab793536851044ea1626026c48614b3021d
|
4
|
+
data.tar.gz: e701c25efe30f3572cd36393bd5f5e376291ace4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f318ee63dce722aa3ca763eedf1ae4268d1575e9f0a7bb3c9df28df34beac941cbf49cd4dffc43253cab7cfb1dfb9a904ef67ee49504c9168faa949d83e8c7e9
|
7
|
+
data.tar.gz: ac3a2c27e106f41928808fc9c2074c6ed4a5e2a5a5245cba24c3611106d6c81dab04242ba552aeff93e995d36859382443c259f4f87b7fffef1c1636b7d76420
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
data/doc/ChangeLog
CHANGED
data/kmeans.gemspec
CHANGED
@@ -2,14 +2,15 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
+
# stub: kmeans 0.1.1 ruby lib
|
5
6
|
|
6
7
|
Gem::Specification.new do |s|
|
7
8
|
s.name = "kmeans"
|
8
|
-
s.version = "0.1.
|
9
|
+
s.version = "0.1.1"
|
9
10
|
|
10
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
12
|
s.authors = ["id774"]
|
12
|
-
s.date = "2013-
|
13
|
+
s.date = "2013-09-30"
|
13
14
|
s.description = "K-means clustering"
|
14
15
|
s.email = "idnanashi@gmail.com"
|
15
16
|
s.extra_rdoc_files = [
|
@@ -48,11 +49,11 @@ Gem::Specification.new do |s|
|
|
48
49
|
s.homepage = "http://github.com/id774/kmeans"
|
49
50
|
s.licenses = ["GPL"]
|
50
51
|
s.require_paths = ["lib"]
|
51
|
-
s.rubygems_version = "1.
|
52
|
+
s.rubygems_version = "2.1.3"
|
52
53
|
s.summary = "kmeans"
|
53
54
|
|
54
55
|
if s.respond_to? :specification_version then
|
55
|
-
s.specification_version =
|
56
|
+
s.specification_version = 4
|
56
57
|
|
57
58
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
58
59
|
s.add_development_dependency(%q<cucumber>, [">= 0"])
|
data/lib/kmeans.rb
CHANGED
data/lib/kmeans/cluster.rb
CHANGED
@@ -23,9 +23,8 @@ module Kmeans
|
|
23
23
|
old_centroids = nil
|
24
24
|
until (@centroids == old_centroids) or (@options[:loop_max] < loop_counter)
|
25
25
|
loop_counter += 1
|
26
|
-
|
26
|
+
attach_keys_to_nearest_centroid
|
27
27
|
old_centroids = Marshal.load(Marshal.dump(@centroids))
|
28
|
-
|
29
28
|
@centroids.each_key {|centroid|
|
30
29
|
@centroids[centroid] = average_attached(centroid) if @cluster[centroid].any?
|
31
30
|
}
|
@@ -33,11 +32,12 @@ module Kmeans
|
|
33
32
|
end
|
34
33
|
|
35
34
|
private
|
35
|
+
|
36
36
|
def min_and_max_in_word_counts
|
37
37
|
all_counts = Hash.new {|hash, key| hash[key] = []}
|
38
38
|
min_and_max = {}
|
39
39
|
|
40
|
-
@word_counts.each {|
|
40
|
+
@word_counts.each {|key, counts|
|
41
41
|
counts.each {|word, count|
|
42
42
|
all_counts[word] << count.to_i
|
43
43
|
}
|
@@ -46,7 +46,8 @@ module Kmeans
|
|
46
46
|
all_counts.each {|word, counts|
|
47
47
|
min_and_max[word] = Pair.new [counts.min, counts.max]
|
48
48
|
}
|
49
|
-
|
49
|
+
|
50
|
+
return min_and_max
|
50
51
|
end
|
51
52
|
|
52
53
|
def random_centroids
|
@@ -59,42 +60,45 @@ module Kmeans
|
|
59
60
|
}
|
60
61
|
centroids[centroid] = random_counts
|
61
62
|
}
|
62
|
-
|
63
|
+
|
64
|
+
return centroids
|
63
65
|
end
|
64
66
|
|
65
|
-
def
|
67
|
+
def attach_keys_to_nearest_centroid
|
66
68
|
@cluster.clear
|
67
69
|
|
68
|
-
@word_counts.each_key {|
|
69
|
-
@cluster[nearest_centroid(
|
70
|
+
@word_counts.each_key {|key|
|
71
|
+
@cluster[nearest_centroid(key)] << key
|
70
72
|
}
|
71
73
|
end
|
72
74
|
|
73
|
-
def nearest_centroid(
|
75
|
+
def nearest_centroid(key)
|
74
76
|
correlations = @centroids.map {|centroid, centroid_word_count|
|
75
|
-
|
77
|
+
all_counts = []
|
76
78
|
centroid_counts = []
|
77
79
|
|
78
|
-
@word_counts[
|
80
|
+
@word_counts[key].each {|word, count|
|
79
81
|
count = 0 unless count.class == Fixnum
|
80
|
-
|
82
|
+
all_counts << count
|
81
83
|
centroid_counts << centroid_word_count[word]
|
82
84
|
}
|
83
|
-
1 - Pearson.calc(
|
85
|
+
centroid_counts.empty? ? 0 : 1 - Pearson.calc(all_counts, centroid_counts)
|
84
86
|
}
|
85
|
-
|
87
|
+
|
88
|
+
return correlations.rindex(correlations.min {|x, y| x.abs <=> y.abs })
|
86
89
|
end
|
87
90
|
|
88
91
|
def average_attached(centroid)
|
89
|
-
average_word_counts = @cluster[centroid].map {|
|
90
|
-
@centroids[centroid].keys.map {|word| @word_counts[
|
92
|
+
average_word_counts = @cluster[centroid].map {|key|
|
93
|
+
@centroids[centroid].keys.map {|word| @word_counts[key][word]}
|
91
94
|
}.transpose.map {|all_counts|
|
92
95
|
all_counts.inject(0) {|sum, count|
|
93
96
|
count = 0 unless count.class == Fixnum
|
94
97
|
sum + count
|
95
98
|
}.quo(all_counts.size)
|
96
99
|
}
|
97
|
-
|
100
|
+
|
101
|
+
return Hash[*@centroids[centroid].keys.zip(average_word_counts).flatten]
|
98
102
|
end
|
99
103
|
end
|
100
104
|
end
|
data/lib/kmeans/dendrogram.rb
CHANGED
data/lib/kmeans/hcluster.rb
CHANGED
@@ -33,6 +33,7 @@ module Kmeans
|
|
33
33
|
end
|
34
34
|
printclust(clust.left, labels, n+1) if clust.left != nil
|
35
35
|
printclust(clust.right, labels, n+1) if clust.right != nil
|
36
|
+
|
36
37
|
return @out
|
37
38
|
end
|
38
39
|
|
@@ -76,6 +77,7 @@ module Kmeans
|
|
76
77
|
clust.delete_at(lowestpair[0])
|
77
78
|
clust.push(newcluster)
|
78
79
|
end
|
80
|
+
|
79
81
|
return clust[0]
|
80
82
|
end
|
81
83
|
end
|
@@ -135,6 +135,41 @@ describe Kmeans::Cluster do
|
|
135
135
|
nil=>"1"
|
136
136
|
},
|
137
137
|
}
|
138
|
+
|
139
|
+
@empty_hash = {
|
140
|
+
"test01"=>
|
141
|
+
{"hoge"=>0,
|
142
|
+
"fuga"=>1,
|
143
|
+
"piyo"=>0
|
144
|
+
},
|
145
|
+
"test02"=>
|
146
|
+
{"hoge"=>2,
|
147
|
+
"fuga"=>1,
|
148
|
+
"piyo"=>3
|
149
|
+
},
|
150
|
+
"test03"=>
|
151
|
+
{"hoge"=>3,
|
152
|
+
"fuga"=>0,
|
153
|
+
"poyo"=>1
|
154
|
+
},
|
155
|
+
"test04"=>
|
156
|
+
{"puyo"=>0,
|
157
|
+
"fuga"=>2,
|
158
|
+
"piyo"=>0
|
159
|
+
},
|
160
|
+
"test05"=>
|
161
|
+
{"hoge"=>4,
|
162
|
+
"fuga"=>2,
|
163
|
+
"poyo"=>3
|
164
|
+
},
|
165
|
+
"test06"=>
|
166
|
+
{},
|
167
|
+
"test07"=>
|
168
|
+
{},
|
169
|
+
"test08"=>
|
170
|
+
{}
|
171
|
+
}
|
172
|
+
|
138
173
|
end
|
139
174
|
|
140
175
|
context 'の Cluster クラスにおいて' do
|
@@ -217,5 +252,25 @@ describe Kmeans::Cluster do
|
|
217
252
|
result.cluster.values.class.should be_equal Array
|
218
253
|
end
|
219
254
|
end
|
255
|
+
|
256
|
+
describe '空のハッシュを含む不均一な二次元ハッシュを渡しても' do
|
257
|
+
it "Kmeans::Cluster クラスが返却される" do
|
258
|
+
result = Kmeans::Cluster.new(@empty_hash, {
|
259
|
+
:centroids => 5,
|
260
|
+
:loop_max => 10
|
261
|
+
})
|
262
|
+
result.class.should be_equal Kmeans::Cluster
|
263
|
+
end
|
264
|
+
|
265
|
+
it "ハッシュの配列が返却される (結果は実行ごとに異なる)" do
|
266
|
+
result = Kmeans::Cluster.new(@empty_hash, {
|
267
|
+
:centroids => 5,
|
268
|
+
:loop_max => 10
|
269
|
+
})
|
270
|
+
result.make_cluster
|
271
|
+
result.cluster.class.should be_equal Hash
|
272
|
+
result.cluster.values.class.should be_equal Array
|
273
|
+
end
|
274
|
+
end
|
220
275
|
end
|
221
276
|
end
|
@@ -10,8 +10,8 @@ describe Kmeans::Pair do
|
|
10
10
|
max = 4
|
11
11
|
expect = [0, 4]
|
12
12
|
result = Kmeans::Pair.new([min, max])
|
13
|
-
result[0].should
|
14
|
-
result[1].should
|
13
|
+
result[0].should eql expect[0]
|
14
|
+
result[1].should eql expect[1]
|
15
15
|
end
|
16
16
|
|
17
17
|
it "ペアが返却される" do
|
@@ -19,8 +19,8 @@ describe Kmeans::Pair do
|
|
19
19
|
max = 3
|
20
20
|
expect = [1, 3]
|
21
21
|
result = Kmeans::Pair.new([min, max])
|
22
|
-
result[0].should
|
23
|
-
result[1].should
|
22
|
+
result[0].should eql expect[0]
|
23
|
+
result[1].should eql expect[1]
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
@@ -31,8 +31,8 @@ describe Kmeans::Pair do
|
|
31
31
|
unexpected = 6
|
32
32
|
expect = [2, 4]
|
33
33
|
result = Kmeans::Pair.new([min, max, unexpected])
|
34
|
-
result[0].should
|
35
|
-
result[1].should
|
34
|
+
result[0].should eql expect[0]
|
35
|
+
result[1].should eql expect[1]
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
@@ -42,8 +42,8 @@ describe Kmeans::Pair do
|
|
42
42
|
max = 5
|
43
43
|
expect = [5, 5]
|
44
44
|
result = Kmeans::Pair.new([min, max])
|
45
|
-
result[0].should
|
46
|
-
result[1].should
|
45
|
+
result[0].should eql expect[0]
|
46
|
+
result[1].should eql expect[1]
|
47
47
|
end
|
48
48
|
end
|
49
49
|
end
|
@@ -6,259 +6,259 @@ describe Kmeans::Pearson do
|
|
6
6
|
context 'の Pearson クラスにおいて' do
|
7
7
|
describe '相関係数 0.0 となる集合を渡す場合' do
|
8
8
|
it "ピアソン相関係数が返却される" do
|
9
|
-
|
9
|
+
expected = 0.0
|
10
10
|
v1 = [4,2,3]
|
11
11
|
v2 = [0,0,1]
|
12
12
|
result = Kmeans::Pearson.calc(v1,v2)
|
13
|
-
result.should
|
13
|
+
result.should eql expected
|
14
14
|
end
|
15
15
|
|
16
16
|
it "ピアソン相関係数が返却される" do
|
17
|
-
|
17
|
+
expected = 0.0
|
18
18
|
v1 = [0, 2, 0]
|
19
19
|
v2 = [2, 1, 0]
|
20
20
|
result = Kmeans::Pearson.calc(v1,v2)
|
21
|
-
result.should
|
21
|
+
result.should eql expected
|
22
22
|
end
|
23
23
|
|
24
24
|
it "ピアソン相関係数が返却される" do
|
25
|
-
|
25
|
+
expected = 0.0
|
26
26
|
v1 = [0, 2, 0]
|
27
27
|
v2 = [(3/2), (1/2), (1/2)]
|
28
28
|
result = Kmeans::Pearson.calc(v1,v2)
|
29
|
-
result.should
|
29
|
+
result.should eql expected
|
30
30
|
end
|
31
31
|
|
32
32
|
it "ピアソン相関係数が返却される" do
|
33
|
-
|
33
|
+
expected = 0.0
|
34
34
|
v1 = [4, 2, 3]
|
35
35
|
v2 = [(3/2), (3/2), (1/2)]
|
36
36
|
result = Kmeans::Pearson.calc(v1,v2)
|
37
|
-
result.should
|
37
|
+
result.should eql expected
|
38
38
|
end
|
39
39
|
|
40
40
|
it "ピアソン相関係数が返却される" do
|
41
|
-
|
41
|
+
expected = 0.0
|
42
42
|
v1 = [2, 1, 3]
|
43
43
|
v2 = [(10/3), (1/1), (5/3)]
|
44
44
|
result = Kmeans::Pearson.calc(v1,v2)
|
45
|
-
result.should
|
45
|
+
result.should eql expected
|
46
46
|
end
|
47
47
|
|
48
48
|
it "ピアソン相関係数が返却される" do
|
49
|
-
|
49
|
+
expected = 0.0
|
50
50
|
v1 = [0, 1, 0]
|
51
51
|
v2 = [2, 1, 0]
|
52
52
|
result = Kmeans::Pearson.calc(v1,v2)
|
53
|
-
result.should
|
53
|
+
result.should eql expected
|
54
54
|
end
|
55
55
|
|
56
56
|
it "ピアソン相関係数が返却される" do
|
57
|
-
|
57
|
+
expected = 0.0
|
58
58
|
v1 = [0, 1, 0]
|
59
59
|
v2 = [(10/3), (1/1), (5/3)]
|
60
60
|
result = Kmeans::Pearson.calc(v1,v2)
|
61
|
-
result.should
|
61
|
+
result.should eql expected
|
62
62
|
end
|
63
63
|
|
64
64
|
it "ピアソン相関係数が返却される" do
|
65
|
-
|
65
|
+
expected = 0.0
|
66
66
|
v1 = [0, 2, 0]
|
67
67
|
v2 = [2, 1, 0]
|
68
68
|
result = Kmeans::Pearson.calc(v1,v2)
|
69
|
-
result.should
|
69
|
+
result.should eql expected
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
73
73
|
describe '相関係数が正となる集合を渡す場合' do
|
74
74
|
it "ピアソン相関係数が返却される" do
|
75
|
-
|
75
|
+
expected = 0.31622776601683794
|
76
76
|
v1 = [3, 0, 1]
|
77
77
|
v2 = [(2/1), (1/1), (3/1)]
|
78
78
|
result = Kmeans::Pearson.calc(v1,v2)
|
79
|
-
result.should
|
79
|
+
result.should eql expected
|
80
80
|
end
|
81
81
|
|
82
82
|
it "ピアソン相関係数が返却される" do
|
83
|
-
|
83
|
+
expected = 0.4472135954999579
|
84
84
|
v1 = [3, 0, 1]
|
85
85
|
v2 = [(3/2), (3/2), (1/2)]
|
86
86
|
result = Kmeans::Pearson.calc(v1,v2)
|
87
|
-
result.should
|
87
|
+
result.should eql expected
|
88
88
|
end
|
89
89
|
|
90
90
|
it "ピアソン相関係数が返却される" do
|
91
|
-
|
91
|
+
expected = 0.8944271909999159
|
92
92
|
v1 = [3, 0, 1]
|
93
93
|
v2 = [(3/2), (1/2), (1/2)]
|
94
94
|
result = Kmeans::Pearson.calc(v1,v2)
|
95
|
-
result.should
|
95
|
+
result.should eql expected
|
96
96
|
end
|
97
97
|
|
98
98
|
it "ピアソン相関係数が返却される" do
|
99
|
-
|
99
|
+
expected = 0.5773502691896258
|
100
100
|
v1 = [0, 2, 0]
|
101
101
|
v2 = [(3/2), (3/2), (1/2)]
|
102
102
|
result = Kmeans::Pearson.calc(v1,v2)
|
103
|
-
result.should
|
103
|
+
result.should eql expected
|
104
104
|
end
|
105
105
|
|
106
106
|
it "ピアソン相関係数が返却される" do
|
107
|
-
|
107
|
+
expected = 0.8164965809277261
|
108
108
|
v1 = [4, 2, 3]
|
109
109
|
v2 = [(3/1), (3/2), (3/1)]
|
110
110
|
result = Kmeans::Pearson.calc(v1,v2)
|
111
|
-
result.should
|
111
|
+
result.should eql expected
|
112
112
|
end
|
113
113
|
|
114
114
|
it "ピアソン相関係数が返却される" do
|
115
|
-
|
115
|
+
expected = 0.5
|
116
116
|
v1 = [4, 2, 3]
|
117
117
|
v2 = [2, 1, 0]
|
118
118
|
result = Kmeans::Pearson.calc(v1,v2)
|
119
|
-
result.should
|
119
|
+
result.should eql expected
|
120
120
|
end
|
121
121
|
|
122
122
|
it "ピアソン相関係数が返却される" do
|
123
|
-
|
123
|
+
expected = 0.7071067811865475
|
124
124
|
v1 = [4, 2, 3]
|
125
125
|
v2 = [(3/2), (1/2), (1/2)]
|
126
126
|
result = Kmeans::Pearson.calc(v1,v2)
|
127
|
-
result.should
|
127
|
+
result.should eql expected
|
128
128
|
end
|
129
129
|
|
130
130
|
it "ピアソン相関係数が返却される" do
|
131
|
-
|
131
|
+
expected = 0.6666666666666666
|
132
132
|
v1 = [3, 1, 1]
|
133
133
|
v2 = [(3/1), (3/2), (3/1)]
|
134
134
|
result = Kmeans::Pearson.calc(v1,v2)
|
135
|
-
result.should
|
135
|
+
result.should eql expected
|
136
136
|
end
|
137
137
|
|
138
138
|
it "ピアソン相関係数が返却される" do
|
139
|
-
|
139
|
+
expected = 0.8164965809277261
|
140
140
|
v1 = [3, 1, 1]
|
141
141
|
v2 = [2, 1, 0]
|
142
142
|
result = Kmeans::Pearson.calc(v1,v2)
|
143
|
-
result.should
|
143
|
+
result.should eql expected
|
144
144
|
end
|
145
145
|
|
146
146
|
it "ピアソン相関係数が返却される" do
|
147
|
-
|
147
|
+
expected = 0.5773502691896258
|
148
148
|
v1 = [3, 1, 1]
|
149
149
|
v2 = [(3/2), (3/2), (1/2)]
|
150
150
|
result = Kmeans::Pearson.calc(v1,v2)
|
151
|
-
result.should
|
151
|
+
result.should eql expected
|
152
152
|
end
|
153
153
|
|
154
154
|
it "ピアソン相関係数が返却される" do
|
155
|
-
|
155
|
+
expected = 0.31622776601683794
|
156
156
|
v1 = [3, 0, 1]
|
157
157
|
v2 = [(2/1), (1/1), (3/1)]
|
158
158
|
result = Kmeans::Pearson.calc(v1,v2)
|
159
|
-
result.should
|
159
|
+
result.should eql expected
|
160
160
|
end
|
161
161
|
|
162
162
|
it "ピアソン相関係数が返却される" do
|
163
|
-
|
163
|
+
expected = 0.6324555320336759
|
164
164
|
v1 = [3, 0, 1]
|
165
165
|
v2 = [2, 1, 0]
|
166
166
|
result = Kmeans::Pearson.calc(v1,v2)
|
167
|
-
result.should
|
167
|
+
result.should eql expected
|
168
168
|
end
|
169
169
|
end
|
170
170
|
|
171
171
|
describe '相関係数が負となる集合を渡す場合' do
|
172
172
|
it "ピアソン相関係数が返却される" do
|
173
|
-
|
173
|
+
expected = -0.6666666666666666
|
174
174
|
v1 = [0, 2, 0]
|
175
175
|
v2 = [(3/1), (3/2), (3/1)]
|
176
176
|
result = Kmeans::Pearson.calc(v1,v2)
|
177
|
-
result.should
|
177
|
+
result.should eql expected
|
178
178
|
end
|
179
179
|
|
180
180
|
it "ピアソン相関係数が返却される" do
|
181
|
-
|
181
|
+
expected = -0.4472135954999579
|
182
182
|
v1 = [3, 0, 1]
|
183
183
|
v2 = [(0/1), (3/2), (0/1)]
|
184
184
|
result = Kmeans::Pearson.calc(v1,v2)
|
185
|
-
result.should
|
185
|
+
result.should eql expected
|
186
186
|
end
|
187
187
|
|
188
188
|
it "ピアソン相関係数が返却される" do
|
189
|
-
|
189
|
+
expected = -0.8164965809277261
|
190
190
|
v1 = [0, 2, 0]
|
191
191
|
v2 = [(2/1), (1/1), (3/1)]
|
192
192
|
result = Kmeans::Pearson.calc(v1,v2)
|
193
|
-
result.should
|
193
|
+
result.should eql expected
|
194
194
|
end
|
195
195
|
|
196
196
|
it "ピアソン相関係数が返却される" do
|
197
|
-
|
197
|
+
expected = -0.7071067811865475
|
198
198
|
v1 = [0, 1, 0]
|
199
199
|
v2 = [(2/1), (1/1), (3/1)]
|
200
200
|
result = Kmeans::Pearson.calc(v1,v2)
|
201
|
-
result.should
|
201
|
+
result.should eql expected
|
202
202
|
end
|
203
203
|
|
204
204
|
it "ピアソン相関係数が返却される" do
|
205
|
-
|
205
|
+
expected = -0.5
|
206
206
|
v1 = [2, 1, 3]
|
207
207
|
v2 = [2, 1, 0]
|
208
208
|
result = Kmeans::Pearson.calc(v1,v2)
|
209
|
-
result.should
|
209
|
+
result.should eql expected
|
210
210
|
end
|
211
211
|
|
212
212
|
it "ピアソン相関係数が返却される" do
|
213
|
-
|
213
|
+
expected = -0.7071067811865475
|
214
214
|
v1 = [2, 1, 3]
|
215
215
|
v2 = [(0/1), (3/2), (0/1)]
|
216
216
|
result = Kmeans::Pearson.calc(v1,v2)
|
217
|
-
result.should
|
217
|
+
result.should eql expected
|
218
218
|
end
|
219
219
|
end
|
220
220
|
|
221
221
|
describe '相関係数が 1.0 の場合' do
|
222
222
|
it "ピアソン相関係数が返却される" do
|
223
|
-
|
223
|
+
expected = 1.0
|
224
224
|
v1 = [0, 1, 0]
|
225
225
|
v2 = [(0/1), (3/2), (0/1)]
|
226
226
|
result = Kmeans::Pearson.calc(v1,v2)
|
227
|
-
result.should
|
227
|
+
result.should eql expected
|
228
228
|
end
|
229
229
|
|
230
230
|
it "ピアソン相関係数が返却される" do
|
231
|
-
|
231
|
+
expected = 1.0
|
232
232
|
v1 = [2, 1, 3]
|
233
233
|
v2 = [(2/1), (1/1), (3/1)]
|
234
234
|
result = Kmeans::Pearson.calc(v1,v2)
|
235
|
-
result.should
|
235
|
+
result.should eql expected
|
236
236
|
end
|
237
237
|
end
|
238
238
|
|
239
239
|
describe '相関係数が 1 を越える場合' do
|
240
240
|
it "ピアソン相関係数が返却される" do
|
241
|
-
|
241
|
+
expected = 1.0327955589886444
|
242
242
|
v1 = [3, 0, 1]
|
243
243
|
v2 = [(10/3), (1/1), (5/3)]
|
244
244
|
result = Kmeans::Pearson.calc(v1,v2)
|
245
|
-
result.should
|
245
|
+
result.should eql expected
|
246
246
|
end
|
247
247
|
|
248
248
|
it "ピアソン相関係数が返却される" do
|
249
|
-
|
249
|
+
expected = 1.1547005383792517
|
250
250
|
v1 = [0, 2, 0]
|
251
251
|
v2 = [(0/1), (3/2), (0/1)]
|
252
252
|
result = Kmeans::Pearson.calc(v1,v2)
|
253
|
-
result.should
|
253
|
+
result.should eql expected
|
254
254
|
end
|
255
255
|
|
256
256
|
it "ピアソン相関係数が返却される" do
|
257
|
-
|
257
|
+
expected = 1.1547005383792517
|
258
258
|
v1 = [3, 1, 1]
|
259
259
|
v2 = [(3/2), (1/2), (1/2)]
|
260
260
|
result = Kmeans::Pearson.calc(v1,v2)
|
261
|
-
result.should
|
261
|
+
result.should eql expected
|
262
262
|
end
|
263
263
|
end
|
264
264
|
end
|
data/spec/lib/kmeans_spec.rb
CHANGED
metadata
CHANGED
@@ -1,62 +1,55 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kmeans
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
5
|
-
prerelease:
|
4
|
+
version: 0.1.1
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- id774
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-09-30 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: cucumber
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - '>='
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: bundler
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - '>='
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - '>='
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: jeweler
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - '>='
|
52
46
|
- !ruby/object:Gem::Version
|
53
47
|
version: '0'
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - '>='
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: '0'
|
62
55
|
description: K-means clustering
|
@@ -97,26 +90,25 @@ files:
|
|
97
90
|
homepage: http://github.com/id774/kmeans
|
98
91
|
licenses:
|
99
92
|
- GPL
|
93
|
+
metadata: {}
|
100
94
|
post_install_message:
|
101
95
|
rdoc_options: []
|
102
96
|
require_paths:
|
103
97
|
- lib
|
104
98
|
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
-
none: false
|
106
99
|
requirements:
|
107
|
-
- -
|
100
|
+
- - '>='
|
108
101
|
- !ruby/object:Gem::Version
|
109
102
|
version: '0'
|
110
103
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
|
-
none: false
|
112
104
|
requirements:
|
113
|
-
- -
|
105
|
+
- - '>='
|
114
106
|
- !ruby/object:Gem::Version
|
115
107
|
version: '0'
|
116
108
|
requirements: []
|
117
109
|
rubyforge_project:
|
118
|
-
rubygems_version: 1.
|
110
|
+
rubygems_version: 2.1.3
|
119
111
|
signing_key:
|
120
|
-
specification_version:
|
112
|
+
specification_version: 4
|
121
113
|
summary: kmeans
|
122
114
|
test_files: []
|