
hex.ModelMetricsClustering Maven / Gradle / Ivy
package hex;
import hex.ClusteringModel.ClusteringOutput;
import hex.ClusteringModel.ClusteringParameters;
import water.exceptions.H2OIllegalArgumentException;
import water.fvec.Frame;
import water.util.ArrayUtils;
import water.util.TwoDimTable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class ModelMetricsClustering extends ModelMetricsUnsupervised {
public long[/*k*/] _size;
public double[/*k*/] _withinss;
public double _totss;
public double _tot_withinss;
public double _betweenss;
// public TwoDimTable _centroid_stats;
public double totss() { return _totss; }
public double tot_withinss() { return _tot_withinss; }
public double betweenss() { return _betweenss; }
public ModelMetricsClustering(Model model, Frame frame) {
super(model, frame, Double.NaN);
_size = null;
_withinss = null;
_totss = _tot_withinss = _betweenss = Double.NaN;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(super.toString());
sb.append(" total sum of squares: " + (float)_totss + "\n");
sb.append(" total within sum of squares: " + (float)_tot_withinss + "\n");
sb.append(" total between sum of squares: " + (float)_betweenss + "\n");
if (_size != null) sb.append(" per cluster sizes: " + Arrays.toString(_size) + "\n");
if (_withinss != null) sb.append(" per cluster within sum of squares: " + Arrays.toString(_withinss) + "\n");
return sb.toString();
}
/**
* Populate TwoDimTable from members _size and _withinss
* @return TwoDimTable
*/
public TwoDimTable createCentroidStatsTable() {
if (_size == null || _withinss == null)
return null;
List colHeaders = new ArrayList<>();
List colTypes = new ArrayList<>();
List colFormat = new ArrayList<>();
colHeaders.add("Centroid"); colTypes.add("long"); colFormat.add("%d");
colHeaders.add("Size"); colTypes.add("double"); colFormat.add("%.5f");
colHeaders.add("Within Cluster Sum of Squares"); colTypes.add("double"); colFormat.add("%.5f");
final int K = _size.length;
assert(_withinss.length == K);
TwoDimTable table = new TwoDimTable(
"Centroid Statistics", null,
new String[K],
colHeaders.toArray(new String[0]),
colTypes.toArray(new String[0]),
colFormat.toArray(new String[0]),
"");
for (int k =0; k
© 2015 - 2025 Weber Informatics LLC | Privacy Policy