kmeans 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/doc/ChangeLog +5 -0
- data/kmeans.gemspec +2 -2
- data/lib/kmeans.rb +1 -1
- data/lib/kmeans/cluster.rb +4 -1
- data/spec/lib/kmeans/cluster_spec.rb +58 -7
- data/spec/lib/kmeans_spec.rb +1 -1
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.6
|
data/doc/ChangeLog
CHANGED
data/kmeans.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "kmeans"
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.6"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["id774"]
|
12
|
-
s.date = "2012-
|
12
|
+
s.date = "2012-11-02"
|
13
13
|
s.description = "K-means clustering"
|
14
14
|
s.email = "idnanashi@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/kmeans.rb
CHANGED
data/lib/kmeans/cluster.rb
CHANGED
@@ -88,7 +88,10 @@ module Kmeans
|
|
88
88
|
average_word_counts = @cluster[centroid].map {|url|
|
89
89
|
@centroids[centroid].keys.map {|word| @word_counts[url][word]}
|
90
90
|
}.transpose.map {|all_counts|
|
91
|
-
all_counts.inject(0) {|sum, count|
|
91
|
+
all_counts.inject(0) {|sum, count|
|
92
|
+
count = 0 unless count.class == Fixnum
|
93
|
+
sum + count
|
94
|
+
}.quo(all_counts.size)
|
92
95
|
}
|
93
96
|
Hash[*@centroids[centroid].keys.zip(average_word_counts).flatten]
|
94
97
|
end
|
@@ -4,7 +4,7 @@ require File.dirname(__FILE__) + '/../../spec_helper'
|
|
4
4
|
|
5
5
|
describe Kmeans::Cluster do
|
6
6
|
before :all do
|
7
|
-
@
|
7
|
+
@uniform_hash = {
|
8
8
|
"test01"=>
|
9
9
|
{"hoge"=>0,
|
10
10
|
"fuga"=>1,
|
@@ -36,23 +36,74 @@ describe Kmeans::Cluster do
|
|
36
36
|
"piyo"=>1
|
37
37
|
}
|
38
38
|
}
|
39
|
+
|
40
|
+
@unequal_hash = {
|
41
|
+
"test01"=>
|
42
|
+
{"hoge"=>0,
|
43
|
+
"fuga"=>1,
|
44
|
+
"piyo"=>0
|
45
|
+
},
|
46
|
+
"test02"=>
|
47
|
+
{"hoge"=>2,
|
48
|
+
"fuga"=>1,
|
49
|
+
"piyo"=>3
|
50
|
+
},
|
51
|
+
"test03"=>
|
52
|
+
{"hoge"=>3,
|
53
|
+
"fuga"=>0,
|
54
|
+
"poyo"=>1
|
55
|
+
},
|
56
|
+
"test04"=>
|
57
|
+
{"puyo"=>0,
|
58
|
+
"fuga"=>2,
|
59
|
+
"piyo"=>0
|
60
|
+
},
|
61
|
+
"test05"=>
|
62
|
+
{"hoge"=>4,
|
63
|
+
"fuga"=>2,
|
64
|
+
"poyo"=>3
|
65
|
+
},
|
66
|
+
"test06"=>
|
67
|
+
{"hoge"=>3,
|
68
|
+
"hohe"=>1,
|
69
|
+
"piyo"=>1
|
70
|
+
}
|
71
|
+
}
|
39
72
|
end
|
40
73
|
|
41
74
|
context 'の Cluster クラスにおいて' do
|
42
|
-
describe '
|
75
|
+
describe 'キーの均一な二次元ハッシュを渡すと' do
|
43
76
|
it "Kmeans::Cluster クラスが返却される" do
|
44
|
-
result = Kmeans::Cluster.new(@
|
45
|
-
:centroids =>
|
77
|
+
result = Kmeans::Cluster.new(@uniform_hash, {
|
78
|
+
:centroids => 5,
|
46
79
|
:loop_max => 10
|
47
80
|
})
|
48
81
|
result.class.should be_equal Kmeans::Cluster
|
49
82
|
end
|
83
|
+
|
84
|
+
it "ハッシュの配列が返却される (結果は実行ごとに異なる)" do
|
85
|
+
result = Kmeans::Cluster.new(@uniform_hash, {
|
86
|
+
:centroids => 5,
|
87
|
+
:loop_max => 10
|
88
|
+
})
|
89
|
+
result.make_cluster
|
90
|
+
result.cluster.class.should be_equal Hash
|
91
|
+
result.cluster.values.class.should be_equal Array
|
92
|
+
end
|
50
93
|
end
|
51
94
|
|
52
|
-
describe '
|
95
|
+
describe 'キーの不均一な二次元ハッシュを渡すと' do
|
96
|
+
it "Kmeans::Cluster クラスが返却される" do
|
97
|
+
result = Kmeans::Cluster.new(@unequal_hash, {
|
98
|
+
:centroids => 5,
|
99
|
+
:loop_max => 10
|
100
|
+
})
|
101
|
+
result.class.should be_equal Kmeans::Cluster
|
102
|
+
end
|
103
|
+
|
53
104
|
it "ハッシュの配列が返却される (結果は実行ごとに異なる)" do
|
54
|
-
result = Kmeans::Cluster.new(@
|
55
|
-
:centroids =>
|
105
|
+
result = Kmeans::Cluster.new(@unequal_hash, {
|
106
|
+
:centroids => 5,
|
56
107
|
:loop_max => 10
|
57
108
|
})
|
58
109
|
result.make_cluster
|
data/spec/lib/kmeans_spec.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kmeans
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-11-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: cucumber
|