Created
August 24, 2011 21:41
-
-
Save rakasaka/1169334 to your computer and use it in GitHub Desktop.
Clustering in Ruby using cluster
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'clusterer' | |
include Clusterer | |
@idf = InverseDocumentFrequency.new() | |
a = Document.new("a lion is a wild feline animal", :idf => @idf).normalize!(@idf) | |
b = Document.new("a dog is a friendly animal", :idf => @idf).normalize!(@idf) | |
c = Document.new("a cat is a feline animal", :idf => @idf).normalize!(@idf) | |
clus = Algorithms.bisecting_kmeans([a,b,c], 2, :maximum_iterations => 5) | |
# Results | |
# [#<Clusterer::Cluster:0x00000101200240 @documents=[{"lion"=>0.5, "wild"=>0.5, "felin"=>0.5, "anim"=>0.5}, {"cat"=>0.6134772025315336, "felin"=>0.5584110143854988, "anim"=>0.5584110143854988}]>, #<Clusterer::Cluster:0x00000101200218 @documents=[{"dog"=>0.4949907352038194, "friendli"=>0.4949907352038194, "anim"=>0.7141206789645324}]>] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment