Class: KMeans

Inherits:
Object show all
Defined in:
lib/k_means.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, options = {}) ⇒ KMeans

Returns a new instance of KMeans.



11
12
13
14
15
16
17
18
19
# File 'lib/k_means.rb', line 11

def initialize(data, options={})
  k = options[:centroids] || 4
  @verbose = options[:verbose] == true ? true : nil
      
  @nodes = Node.create_nodes(data)
  @centroids = Centroid.create_centroids(k, @nodes)
  
  perform_cluster_process
end

Instance Attribute Details

#centroidsObject (readonly)

Returns the value of attribute centroids.



9
10
11
# File 'lib/k_means.rb', line 9

def centroids
  @centroids
end

#nodesObject (readonly)

Returns the value of attribute nodes.



9
10
11
# File 'lib/k_means.rb', line 9

def nodes
  @nodes
end

Instance Method Details

#inspectObject



21
22
23
# File 'lib/k_means.rb', line 21

def inspect
  @centroid_pockets.inspect
end

#viewObject



25
26
27
# File 'lib/k_means.rb', line 25

def view
  @centroid_pockets
end