diff --git a/R/h2o-package/R/Algorithms.R b/R/h2o-package/R/Algorithms.R index 508eeea647..90ff5df6e2 100755 --- a/R/h2o-package/R/Algorithms.R +++ b/R/h2o-package/R/Algorithms.R @@ -1396,6 +1396,14 @@ h2o.predict <- function(object, newdata, ...) { stop(paste("Prediction has not yet been implemented for", class(object))) } + +h2o.makeGLMModel <- function(model, beta) { + if( missing(model) || class(model) != "H2OGLMModel") + stop('Must specify source glm model') + res = .h2o.__remoteSend(model@data@h2o, .h2o.__GLMMakeModel, model=model@key, names = paste(names(beta),sep=","), beta = as.vector(beta)) + .h2o.get.glm(model@data@h2o, as.character(res$destination_key), FALSE) +} + h2o.confusionMatrix <- function(data, reference) { if(class(data) != "H2OParsedData") stop("data must be an H2O parsed dataset") if(class(reference) != "H2OParsedData") stop("reference must be an H2O parsed dataset") diff --git a/R/h2o-package/R/Internal.R b/R/h2o-package/R/Internal.R index 6b6c35ae33..3522fffd59 100644 --- a/R/h2o-package/R/Internal.R +++ b/R/h2o-package/R/Internal.R @@ -179,6 +179,8 @@ h2o.setLogPath <- function(path, type) { .h2o.__PAGE_RemoveVec = "2/RemoveVec.json" .h2o.__PAGE_Order = "2/Order.json" +.h2o.__GLMMakeModel = "2/GLMMakeModel.json" + # client -- Connection object returned from h2o.init(). # page -- URL to access within the H2O server. # parms -- List of parameters to send to the server. diff --git a/R/h2o-package/R/models.R b/R/h2o-package/R/models.R index efa2b8a062..040d8101bd 100644 --- a/R/h2o-package/R/models.R +++ b/R/h2o-package/R/models.R @@ -195,9 +195,9 @@ function(h2o, key, lambda_idx = -1, return_all_lambda = TRUE, pre = "", data = N names(result$coefficients) <- pre$json$glm_model$coefficients_names[idxes] if (!is.null(result$normalized_coefficients)) names(result$normalized_coefficients) <- pre$json$glm_model$coefficients_names[idxes] - if(.isBinomial(pre)) { # build and set the confusion matrix + if(.isBinomial(pre) && !is.null(valid) && !is.null(valid$cms)) { # build and set the confusion matrix cm_ind <- trunc(100*result$best_threshold) + 1 - if ( trunc(100 * result$best_threshold) + 1 > length(valid$cms)) { + if (trunc(100 * result$best_threshold) + 1 > length(valid$cms)) { threshs <- pre$json$glm_model$submodels[[lambda_idx]]$validation$thresholds cm_ind <- which(threshs == result$best_threshold) } diff --git a/src/main/java/hex/glm/GLMModel.java b/src/main/java/hex/glm/GLMModel.java index 79f268dda3..d3ffa0f6fd 100644 --- a/src/main/java/hex/glm/GLMModel.java +++ b/src/main/java/hex/glm/GLMModel.java @@ -52,6 +52,7 @@ public class GLMModel extends Model implements Comparable { @API(help="index of lambda_value giving best results") int best_lambda_idx; + public DataInfo dinfo(){return data_info;} public Key [] xvalModels() { if(submodels == null)return null; for(Submodel sm:submodels) @@ -151,9 +152,7 @@ public int compareTo(GLMModel m){ // fully expanded beta used for scoring private double [] global_beta; - public void setBestSubmodel(double lambda){ - } @API(help="Validation of the null model") public GLMValidation null_validation; @@ -220,6 +219,25 @@ public Submodel(double lambda , double [] beta, double [] norm_beta, long run_ti @API(help = "Variable importances", json=true) VarImp variable_importances; + public GLMModel(GLM2 parameters, Key selfKey, Key dataKey, GLMParams glmp, String [] coefficients_names, double [] beta, DataInfo dinfo, double threshold) { + super(selfKey,dataKey,dinfo._adaptedFrame,null); + this.parameters = (GLM2)parameters.clone(); + submodels = new Submodel[]{new Submodel(0,beta,null,-1,-1,false)}; + this.coefficients_names = coefficients_names; + alpha = 0; + lambda_max = Double.NaN; + this.threshold = threshold; + useAllFactorLevels = dinfo._useAllFactorLevels; + global_beta = submodels[0].beta.clone(); + this.glm = glmp; + this.ymu = Double.NaN; + this.prior = Double.NaN; + this.warnings = new String[]{"Hand made model."}; + this.data_info = dinfo; + this.beta_eps = Double.NaN; + this.job_key = null; + best_lambda_idx = 0; + } public GLMModel(GLM2 job, Key selfKey, DataInfo dinfo, GLMParams glm, GLMValidation nullVal, double beta_eps, double alpha, double lambda_max, double ymu, double prior) { super(selfKey,job.source._key == null ? dinfo._frameKey : job.source._key,dinfo._adaptedFrame, /* priorClassDistribution */ null); parameters = Job.hygiene((GLM2) job.clone()); diff --git a/src/main/java/water/api/RequestServer.java b/src/main/java/water/api/RequestServer.java index ca7bf51ca5..34e77bf916 100644 --- a/src/main/java/water/api/RequestServer.java +++ b/src/main/java/water/api/RequestServer.java @@ -105,7 +105,7 @@ public enum API_VERSION { // Register Inspect2 just for viewing frames registerRequest(new Inspect2()); registerRequest(new MMStats()); - + registerRequest(new GLMMakeModel()); // FVec models Request.addToNavbar(registerRequest(new DeepLearning()),"Deep Learning", "Model"); Request.addToNavbar(registerRequest(new GLM2()), "Generalized Linear Model", "Model");