From 5fca1eb27f8c040964767b1dd59dfc458c23883c Mon Sep 17 00:00:00 2001 From: Tom Kraljevic Date: Mon, 24 Feb 2014 20:33:37 -0800 Subject: [PATCH] PUB-316: Print model specification in HTML output. --- src/main/java/hex/KMeans2.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/hex/KMeans2.java b/src/main/java/hex/KMeans2.java index f14a2b0af9..242a0b7182 100644 --- a/src/main/java/hex/KMeans2.java +++ b/src/main/java/hex/KMeans2.java @@ -63,7 +63,7 @@ public KMeans2() { domain[i] = "Cluster " + i; String[] namesResp = Utils.append(names, "response"); String[][] domaiResp = (String[][]) Utils.append((new Frame(names, vecs)).domains(), (Object) domain); - KMeans2Model model = new KMeans2Model(destination_key, sourceKey, namesResp, domaiResp); + KMeans2Model model = new KMeans2Model(this, destination_key, sourceKey, namesResp, domaiResp); model.delete_and_lock(self()); model.k = k; model.normalized = normalize; model.max_iter = max_iter; @@ -199,6 +199,7 @@ public static Response redirect(Request req, Key model) { @Override public boolean toHTML(StringBuilder sb) { if( model != null ) { + model._params.makeJsonBox(sb); DocGen.HTML.section(sb, "Cluster Centers: "); //"Total Within Cluster Sum of Squares: " + model.total_within_SS); table(sb, "Clusters", model._names, model.centers); double[][] rows = new double[model.within_cluster_variances.length][1]; @@ -290,6 +291,8 @@ public static class KMeans2Model extends Model implements Progress { static final int API_WEAVER = 1; static public DocGen.FieldDoc[] DOC_FIELDS; + private transient final KMeans2 _params; // This is used purely for printing values out. + @API(help = "Cluster centers, always denormalized") public double[][] centers; @@ -330,8 +333,9 @@ public static class KMeans2Model extends Model implements Progress { private transient double[][] _normClust; private transient double[] _means, _mults; - public KMeans2Model(Key selfKey, Key dataKey, String names[], String domains[][]) { + public KMeans2Model(KMeans2 params, Key selfKey, Key dataKey, String names[], String domains[][]) { super(selfKey, dataKey, names, domains); + _params = params; _clustersKey = Key.make(selfKey.toString() + "_clusters"); }