forked from h2oai/h2o-2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge commit '7eb7023673a8547e6bed64af808a4f4b72a563de' into brandon-…
…fixes * commit '7eb7023673a8547e6bed64af808a4f4b72a563de': push a beta_constraints test for tomas add beta_constraints to smalldata fix beta_constraints name h2o.saveAll edited to handle duplicate/xval models Updated PDF for discussion in https://0xdata.atlassian.net/browse/HEX-1814 gets a write lock exception. Can look at the test and sandbox/commands.log and decide if you think the h2o architecture is doing what it's designed to do, or if this is a temporal state that might go away in time, or the test is not-supported user behavior. depends on your point of view, I think? add Tableau+R demo test Update Tableau demo notebook for h2o.ddply instead of ddply. clean up of commented out code R Vignette edited for structure and R code save model check for null xvalmodels in GLM first, fixes null pointer exception
- Loading branch information
Showing
10 changed files
with
221 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
R/tests/testdir_algos/glm/runit_NOPASS_GLM_prostate_beta_constraints.R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
setwd(normalizePath(dirname(R.utils::commandArgs(asValues=TRUE)$"f"))) | ||
source('../../findNSourceUtils.R') | ||
|
||
test.GLM.prostate <- function(conn) { | ||
Log.info("Importing prostate.csv data...\n") | ||
prostate.hex <- h2o.importFile(conn, "https://raw.github.com/0xdata/h2o/master/smalldata/logreg/prostate.csv", "prostate.hex") | ||
beta_constraints <- h2o.importFile(conn, "https://raw.github.com/0xdata/h2o/master/smalldata/beta_constraints.csv") | ||
glm <- h2o.glm(x = 3:9, y = 2, data = prostate.hex, family = "binomial", beta_constraints = beta_constraints) | ||
testEnd() | ||
} | ||
|
||
doTest("GLM Test: Prostate", test.GLM.prostate) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
## | ||
# Test out the h2o.gbm R demo | ||
# It imports a dataset, parses it, and prints a summary | ||
# Then, it runs h2o.gbm on a subset of the dataset | ||
## | ||
|
||
setwd(normalizePath(dirname(R.utils::commandArgs(asValues=TRUE)$"f"))) | ||
source('../findNSourceUtils.R') | ||
|
||
test.tableau <- function(conn) { | ||
Log.info ('Check cluster status') | ||
h2o.clusterInfo(conn) | ||
Log.info ('Importing data into H2O') | ||
data.hex = h2o.importFile(conn, normalizePath(locate('smalldata/airlines/allyears2k_headers.zip'))) | ||
|
||
Log.info ('Grouping flights by months...') | ||
numFlights = h2o.ddply(data.hex, 'Month', nrow) | ||
numFlights.R = as.data.frame(numFlights) | ||
|
||
Log.info ('Grouping number of cancellations by months...') | ||
fun2 = function(df) {sum(df$Cancelled)} | ||
h2o.addFunction(conn, fun2) | ||
cancelledFlights = h2o.ddply(data.hex, 'Month', fun2) | ||
cancelledFlights.R = as.data.frame(cancelledFlights) | ||
|
||
Log.info ('Grouping flights by airport...') | ||
originFlights = h2o.ddply(data.hex, 'Origin', nrow) | ||
originFlights.R = as.data.frame(originFlights) | ||
|
||
Log.info ('Grouping number of cancellations by airport...') | ||
origin_cancelled = h2o.ddply(data.hex, 'Origin', fun2) | ||
origin_cancelled.R = as.data.frame(origin_cancelled) | ||
|
||
.arg2 = 'Origin,Dest,UniqueCarrier' | ||
xvars = unlist( strsplit( .arg2, split = ',' , fixed = TRUE ) ) | ||
data.glm = h2o.glm(x = xvars , y = 'Cancelled', data = data.hex, family = 'binomial', nfolds = 0, standardize=TRUE) | ||
|
||
glmModelTemp = eval(parse(text = 'data.glm' )) | ||
originFactors = levels(data.hex$Origin) | ||
## Tableau grab coefficients corresponding to predictor variable | ||
.arg1 = originFactors | ||
tableau_catFormat <- function( modelKey , variableStr, predictorVariable) { | ||
if( typeof(modelKey) != 'S4') print('Model Key is not in expected format of S4') | ||
if( is.character(variableStr) != TRUE) print('Input column is not in expected format of string') | ||
if( is.character(predictorVariable) != TRUE) print('Input variables is not in expected format of string') | ||
glmModelTemp = modelKey | ||
modelCoeff = modelKey@model$coefficients | ||
modelCoeff = modelKey@model$coefficients | ||
idx = grep( variableStr , names(modelCoeff)) | ||
modelCoeff2 = modelCoeff[idx] | ||
variableNames = unlist(strsplit(names(modelCoeff2),split='.',fixed=TRUE)) | ||
variableNamesMatrix = matrix(variableNames, ncol=2, byrow=TRUE) | ||
variableList = variableNamesMatrix[,2] | ||
names(modelCoeff2) = variableList | ||
setDiff = setdiff(.arg1,variableList) | ||
nullVec = rep(0,length(setDiff)) | ||
names(nullVec) = setDiff | ||
newCoefficientList = c(modelCoeff2, nullVec) | ||
tableau_input = newCoefficientList[predictorVariable] | ||
tableau_input} | ||
|
||
Log.info ('Finish setting up for Tableau function') | ||
sapply(originFactors, function(factor) tableau_catFormat( glmModelTemp, 'Origin' , factor) ) | ||
|
||
testEnd() | ||
} | ||
|
||
doTest("Test out the script used in tableau worksheet", test.tableau) |
Oops, something went wrong.