Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

36 Refactoring demo

  • Loading branch information...
commit 8ea7a86e2cf05360aafd640d26613b24ce87f4b8 1 parent 11d9ab3
@id774 authored
Showing with 14 additions and 10 deletions.
  1. +14 −10 demo.rb
View
24 demo.rb
@@ -7,19 +7,23 @@
require 'lib/kmeans/pearson'
require 'lib/kmeans/cluster'
-uniform_hash = {
-"test01"=> {"hoge"=>0, "fuga"=>1, "piyo"=>0 },
-"test02"=> {"hoge"=>2, "fuga"=>1, "piyo"=>3 },
-"test03"=> {"hoge"=>3, "fuga"=>0, "piyo"=>1 },
-"test04"=> {"hoge"=>0, "fuga"=>2, "piyo"=>0 },
-"test05"=> {"hoge"=>4, "fuga"=>2, "piyo"=>3 },
-"test06"=> {"hoge"=>3, "fuga"=>1, "piyo"=>1 }}
+hash = {
+ "test01"=> {"hoge"=>0, "fuga"=>1, "piyo"=>0 },
+ "test02"=> {"hoge"=>2, "fuga"=>1, "piyo"=>3 },
+ "test03"=> {"hoge"=>3, "fuga"=>0, "piyo"=>1 },
+ "test04"=> {"hoge"=>0, "fuga"=>2, "piyo"=>0 },
+ "test05"=> {"hoge"=>4, "fuga"=>2, "piyo"=>3 },
+ "test06"=> {"hoge"=>3, "fuga"=>1, "piyo"=>1 }
+}
-result = Kmeans::Cluster.new(uniform_hash, {
+kmeans = Kmeans::Cluster.new(hash, {
:centroids => 3,
:loop_max => 10
})
-result.make_cluster
+
+# Kmeans Clustering
+kmeans.make_cluster
# The results differ for each run
-p result.cluster.values #=> [["test01", "test04"], ["test02"], ["test03", "test05", "test06"]]
+p kmeans.cluster.values #=> [["test01", "test04"], ["test02"], ["test03", "test05", "test06"]]
+
Please sign in to comment.
Something went wrong with that request. Please try again.