Skip to content

Commit

Permalink
Merge branch 'master' of github.com:h2oai/h2o
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasnykodym committed Apr 19, 2015
2 parents 495b930 + 48ae600 commit 1e1d811
Showing 1 changed file with 55 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
###############################################################
#### Test Order of input features for Beta Constraints #######
###############################################################
setwd(normalizePath(dirname(R.utils::commandArgs(asValues=TRUE)$"f")))
source('../../../findNSourceUtils.R')

test.priors <- function(conn) {
Log.info("Import modelStack data into H2O...")
## Import data
homeDir = "/mnt/0xcustomer-datasets/c27/"
pathToFile = paste0(homeDir, "data.csv")
pathToConstraints <- paste0(homeDir, "constraints_indices.csv")
modelStack = h2o.importFile(conn, pathToFile)
bc = h2o.importFile(conn, pathToConstraints)

## Set Parameters (default standardization = T)
indVars = setdiff(as.matrix(bc$names)[,"names"], "Intercept")
depVars = "C3"
totRealProb=0.002912744
higherAccuracy = TRUE
lambda = 0
alpha = 0
family_type = "binomial"

## Take subset of data
Log.info("Subset dataset to only predictor and response variables...")
data.hex = modelStack[,c(indVars, depVars)]
summary(data.hex)

## Run GLM
run_glm <- function(data, beta_constraints){
h2o.glm(x = indVars, y = depVars, data = data, family = family_type, prior = totRealProb, use_all_factor_levels = T,
lambda = 0, higher_accuracy = T, alpha = alpha, beta_constraints = beta_constraints)
}

Log.info("Run GLM with original data and original constraints.")
a = run_glm(data = modelStack, beta_constraints = bc)

Log.info("Run GLM with reordered data and original constraints.")
b = run_glm(data = data.hex, beta_constraints = bc)

Log.info("Run GLM with reordered data and reordered beta constraints ")
bc2 = rbind(bc[6:nrow(bc)], bc[1:5])
c = run_glm(data = data.hex, beta_constraints = bc2)

checkEqualsNumeric(sort(a@model$coefficients),sort(b@model$coefficients))
checkEqualsNumeric(sort(b@model$coefficients),sort(c@model$coefficients))
testEnd()
}

doTest("GLM Test: Beta Constraints with Priors", test.priors)




0 comments on commit 1e1d811

Please sign in to comment.