double [ ] [ ] computeStatsFillModel ( LloydsIterationTask task , KMeansModel model , final Vec [ ] vecs , final double [ ] means , final double [ ] mults , final int [ ] modes , int k ) { // Fill in the model based on original destandardized centers if ( model . _parms . _standardize ) { model . _output . _centers_std_raw = task . _cMeans ; } model . _output . _centers_raw = destandardize ( task . _cMeans , _isCats , means , mults ) ; model . _output . _size = task . _size ; model . _output . _withinss = task . _cSqr ; double ssq = 0 ; // sum squared error for ( int i = 0 ; i < k ; i ++ ) ssq += model . _output . _withinss [ i ] ; // sum squared error all clusters model . _output . _tot_withinss = ssq ; // Sum-of-square distance from grand mean if ( k == 1 ) { model . _output . _totss = model . _output . _tot_withinss ; } else { // If data already standardized, grand mean is just the origin TotSS totss = new TotSS ( means , mults , modes , train ( ) . domains ( ) , train ( ) . cardinality ( ) ) . doAll ( vecs ) ; model . _output . _totss = totss . _tss ; } model . _output . _betweenss = model . _output . _totss - model . _output . _tot_withinss ; // MSE between-cluster model . _output . _iterations ++ ; model . _output . _history_withinss = ArrayUtils . copyAndFillOf ( model . _output . _history_withinss , model . _output . _history_withinss . length + 1 , model . _output . _tot_withinss ) ; model . _output . _k = ArrayUtils . copyAndFillOf ( model . _output . _k , model . _output . _k . length + 1 , k ) ; model . _output . _training_time_ms = ArrayUtils . copyAndFillOf ( model . _output . _training_time_ms , model . _output . _training_time_ms . length + 1 , System . currentTimeMillis ( ) ) ; model . _output . _reassigned_count = ArrayUtils . copyAndFillOf ( model . _output . _reassigned_count , model . _output . _reassigned_count . length + 1 , task . _reassigned_count ) ; // Two small TwoDimTables - cheap model . _output . _model_summary = createModelSummaryTable ( model . _output ) ; model . _output . _scoring_history = createScoringHistoryTable ( model . _output ) ; // Take the cluster stats from the model, and assemble them into a model metrics object model . _output . _training_metrics = makeTrainingMetrics ( model ) ; return task . _cMeans ; // New centers }
etc ) . Return new centers .