Skip to content

yja938882/K-Means

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

59 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

K-Means

example1 example2

https://yja938882.github.io/d3_practice/k_means.html

Load

<script type="text/javascript" src="/* path */k_means.js"></script>

DataFormat

var Data = [
 [0.5, 0.7],
 [3.6, 0.11],
 ...
];

Docs

  Constructor


  • K_Means(args)
var kmeans = K_Means( { k : 3, data : [[0.5], [0.6], ... ] });
  • args Object
    • k Number : # of clusters.
    • data Array : Array of data points.



   Methods


  • clustering(dist, callback1, callback2, callback3)
/* Clustring. */
kmeans.clustering(kmeans.euclidean, render1, render2, render3);
  • dist Function : Distance function.
  • callback1 Function : Function that is called after Assignment Step.
  • callback2 Function : Function that is called after Update Step.
  • callback3 Function : Function that is called after clustering.



  • setNearestCluster(dist, callback)
/* Assignment Step. Assign each observation to the cluster. */
kmeans.setNearsetCluster(kmeans.euclidean, render);
  • dist Function : Distance function.
  • callback Function : Function that is called after Update Step.



  • updateCentroid(callback)
/* Update Step. Calculate the new means to be the centroids */
kmeans.updateCentroid(render);
  • callback Function : Function that is called after Update Step.



  • euclidean(pointA, pointB)
/* Euclidean distance function. */
var dist = kmeans.euclidean(pointA, pointB);
  • pointA Array<Number> : point.
  • pointB Array<Number> : point.



  • manhattan(pointA, pointB)
/* Manhattan distance function. */
var dist = kmeans.manhattan( pointA, pointB);
  • pointA Array<Number> : point.
  • pointB Array<Number> : point.

Releases

No releases published

Packages

No packages published