Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package hex.kmeans;
import hex.Model;
import hex.schemas.KMeansModelV2;
import water.Key;
import water.api.ModelSchema;
import water.fvec.*;
public class KMeansModel extends Model {
public static class KMeansParameters extends Model.Parameters {
public int _K; // Number of clusters
public int _max_iters = 1000; // Max iterations
public boolean _normalize = true; // Normalize columns
public long _seed = System.nanoTime(); // RNG seed
public KMeans.Initialization _init = KMeans.Initialization.Furthest;
}
public static class KMeansOutput extends Model.Output {
// Number of categorical variables in the training set; they are all moved
// up-front and use a different distance metric than numerical variables
public int _ncats;
// Iterations executed
public int _iters;
// Cluster centers. During model init, might be null or might have a "K"
// which is oversampled alot. Not normalized (although if normalization is
// used during the building process, the *builders* clusters are normalized).
public double[/*K*/][/*features*/] _clusters;
// Rows per cluster
public long[/*K*/] _rows;
// Sum squared distance between each point and its cluster center, divided by rows
public double[/*K*/] _mses; // Per-cluster MSE, variance
// Sum squared distance between each point and its cluster center, divided by rows.
public double _mse; // Total MSE, variance
public KMeansOutput( KMeans b ) { super(b); }
/** Override because base class implements ncols-1 for features with the
* last column as a response variable; for KMeans all the columns are
* features. */
@Override public int nfeatures() { return _names.length; }
@Override public ModelCategory getModelCategory() {
return Model.ModelCategory.Clustering;
}
}
public KMeansModel(Key selfKey, KMeansParameters parms, KMeansOutput output) { super(selfKey,parms,output); }
@Override
public boolean isSupervised() {return false;}
// Default publically visible Schema is V2
@Override public ModelSchema schema() { return new KMeansModelV2(); }
@Override protected float[] score0(double data[/*ncols*/], float preds[/*nclasses+1*/]) {
preds[0] = KMeans.closest(_output._clusters,data,_output._ncats);
return preds;
}
// public static class KMeans2ModelView extends Request2 {
// static final int API_WEAVER = 1;
// static public DocGen.FieldDoc[] DOC_FIELDS;
//
// @API(help = "KMeans2 Model", json = true, filter = Default.class)
// public KMeans2Model model;
//
// public static String link(String txt, Key model) {
// return "" + txt + "";
// }
//
// public static Response redirect(Request req, Key model) {
// return Response.redirect(req, new KMeans2ModelView().href(), "model", model);
// }
//
// @Override protected Response serve() {
// return Response.done(this);
// }
//
// @Override public boolean toHTML(StringBuilder sb) {
// if( model != null ) {
// model.parameters.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];
// for( int i = 0; i < rows.length; i++ )
// rows[i][0] = model.within_cluster_variances[i];
// columnHTMLlong(sb, "Cluster Size", model.size);
// DocGen.HTML.section(sb, "Cluster Variances: ");
// table(sb, "Clusters", new String[]{"Within Cluster Variances"}, rows);
// columnHTML(sb, "Between Cluster Variances", model.between_cluster_variances);
// sb.append(" ");
// DocGen.HTML.section(sb, "Overall Totals: ");
// double[] row = new double[]{model.total_SS, model.total_within_SS, model.between_cluster_SS};
// rowHTML(sb, new String[]{"Total Sum of Squares", "Total Within Cluster Sum of Squares", "Between Cluster Sum of Squares"}, row);
// DocGen.HTML.section(sb, "Cluster Assignments by Observation: ");
// RString rs = new RString("%content");
// rs.replace("key", model._key + "_clusters");
// rs.replace("content", "View the row-by-row cluster assignments");
// sb.append(rs.toString());
// //sb.append("" );
// return true;
// }
// return false;
// }
//
// private static void rowHTML(StringBuilder sb, String[] header, double[] ro) {
// sb.append("");
// sb.append("