require 'ai4r'

data = [[1,1,1], [3,3,3],[9,9,9]]
ai4r_data = Ai4r::Data::DataSet.new(:data_items=> data)

kmeans = Ai4r::Clusterers::KMeans.new

#abuild(dataset,clusters)

res=kmeans.build(ai4r_data,2)

puts res.inspect

puts res.centroids.join(',')

 

Euclidean distance

http://en.wikipedia.org/wiki/Euclidean_space

http://en.wikipedia.org/wiki/Euclidean_distance

 

dis = Ai4r::Clusterers::KMeans.new

a = [1,1]
b = [3,3]


puts Math.sqrt(dis.distance(a,b))


都是幻覺,嚇不倒我的   (  ̄ c ̄)y▂ξ

igogo 發表在 痞客邦 留言(0) 人氣()