Class: KMeans

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of KMeans.



7
8
9
10
11
12
13
14
15
# File 'lib/k_means/k_means.rb', line 7

def initialize(data, options={})
  distance_measure = options[:distance_measure] || :euclidean_distance
  @nodes = Node.create_nodes(data, distance_measure)
  @centroids = options[:custom_centroids] ||
    Centroid.create_centroids(options[:centroids] || 4, @nodes)
  @verbose = options[:verbose]

  perform_cluster_process
end

Instance Attribute Details

#centroidsObject (readonly)

Returns the value of attribute centroids.



5
6
7
# File 'lib/k_means/k_means.rb', line 5

def centroids
  @centroids
end

#nodesObject (readonly)

Returns the value of attribute nodes.



5
6
7
# File 'lib/k_means/k_means.rb', line 5

def nodes
  @nodes
end

Instance Method Details

#inspectObject



17
18
19
# File 'lib/k_means/k_means.rb', line 17

def inspect
  @centroid_pockets.inspect
end

#viewObject



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

def view
  @centroid_pockets
end