build/modelscript.umd.js
function cluster(k) {
                var Centroids = this.createCentroids(k);
                var LastDistances = Matrix$d.Zero(this.Observations.rows(), this.Observations.cols());
                var Distances = this.distanceFrom(Centroids);
                var Groups;

                while(!(LastDistances.eql(Distances))) {
                Groups = Distances.minColumnIndexes();
                LastDistances = Distances;

                var newCentroids = [];

                for(var i = 1; i <= Centroids.rows(); i++) {
                    var centroid = [];

                    for(var j = 1; j <= Centroids.cols(); j++) {
                    var sum = 0;
                    var count = 0;

                    for(var l = 1; l <= this.Observations.rows(); l++) {
                        if(Groups.e(l) == i) {
                        count++;
                        sum += this.Observations.e(l, j);
                        }
                    }

                    centroid.push(sum / count);
                    }

                    newCentroids.push(centroid);
                }

                Centroids = $M(newCentroids);
                Distances = this.distanceFrom(Centroids);
                }

                return Groups;
            }
function cluster(k) {
                var Centroids = this.createCentroids(k);
                var LastDistances = Matrix$d.Zero(this.Observations.rows(), this.Observations.cols());
                var Distances = this.distanceFrom(Centroids);
                var Groups;

                while(!(LastDistances.eql(Distances))) {
                Groups = Distances.minColumnIndexes();
                LastDistances = Distances;

                var newCentroids = [];

                for(var i = 1; i <= Centroids.rows(); i++) {
                    var centroid = [];

                    for(var j = 1; j <= Centroids.cols(); j++) {
                    var sum = 0;
                    var count = 0;

                    for(var l = 1; l <= this.Observations.rows(); l++) {
                        if(Groups.e(l) == i) {
                        count++;
                        sum += this.Observations.e(l, j);
                        }
                    }

                    centroid.push(sum / count);
                    }

                    newCentroids.push(centroid);
                }

                Centroids = $M(newCentroids);
                Distances = this.distanceFrom(Centroids);
                }

                return Groups;
            }
function cluster ( k ) { var Centroids = this . createCentroids ( k ) ; var LastDistances = Matrix$d . Zero ( this . Observations . rows ( ) , this . Observations . cols ( ) ) ; var Distances = this . distanceFrom ( Centroids ) ; var Groups ; while ( ! ( LastDistances . eql ( Distances ) ) ) { Groups = Distances . minColumnIndexes ( ) ; LastDistances = Distances ; var newCentroids = [ ] ; for ( var i = 1 ; i <= Centroids . rows ( ) ; i ++ ) { var centroid = [ ] ; for ( var j = 1 ; j <= Centroids . cols ( ) ; j ++ ) { var sum = 0 ; var count = 0 ; for ( var l = 1 ; l <= this . Observations . rows ( ) ; l ++ ) { if ( Groups . e ( l ) == i ) { count ++ ; sum += this . Observations . e ( l , j ) ; } } centroid . push ( sum / count ) ; } newCentroids . push ( centroid ) ; } Centroids = $M ( newCentroids ) ; Distances = this . distanceFrom ( Centroids ) ; } return Groups ; }
categorize the feature data X into k clusters. return a vector containing the results.
categorize the feature data X into k clusters . return a vector containing the results .