@@ -262,7 +262,7 @@ h2o.glm <- function(x, y, data, key = "", family, link, nfolds = 0, alpha = 0.5,
262
262
epsilon = 1e-4 , standardize = TRUE , prior , variable_importances = FALSE , use_all_factor_levels = FALSE ,
263
263
tweedie.p = ifelse(family == " tweedie" , 1.5 , as.numeric(NA )), iter.max = 100 ,
264
264
higher_accuracy = FALSE , lambda_search = FALSE , return_all_lambda = FALSE , max_predictors = - 1 ,
265
- offset , has_intercept = TRUE ) {
265
+ offset , has_intercept = TRUE , non_negative = FALSE ) {
266
266
267
267
if (! is.character(key )) stop(" key must be of class character" )
268
268
if (nchar(key ) > 0 && regexpr(" ^[a-zA-Z_][a-zA-Z0-9_.]*$" , key )[1 ] == - 1 )
@@ -274,6 +274,7 @@ h2o.glm <- function(x, y, data, key = "", family, link, nfolds = 0, alpha = 0.5,
274
274
if (! is.numeric(alpha )) stop(' alpha must be numeric' )
275
275
if ( any(alpha < 0 ) ) stop(' alpha must be >= 0' )
276
276
if (! is.logical(has_intercept )) stop(' has_intercept must be logical' )
277
+ if (! is.logical(non_negative )) stop(' non_negative must be logical' )
277
278
if (missing(offset )) { offset <- " " }
278
279
else {
279
280
if (! is.numeric(offset ) && ! is.character(offset )) stop(" offset must be either an index or column name" )
@@ -329,7 +330,7 @@ h2o.glm <- function(x, y, data, key = "", family, link, nfolds = 0, alpha = 0.5,
329
330
lambda_search = as.numeric(lambda_search ), tweedie_variance_power = tweedie.p ,
330
331
max_predictors = max_predictors , variable_importances = as.numeric(variable_importances ),
331
332
use_all_factor_levels = as.numeric(use_all_factor_levels ), link = link , offset = offset ,
332
- has_intercept = as.numeric(has_intercept ))
333
+ has_intercept = as.numeric(has_intercept ), non_negative = as.numeric( non_negative ) )
333
334
else if (family == " binomial" ) {
334
335
if (missing(prior )) prior = - 1
335
336
res = .h2o.__remoteSend(data @ h2o , .h2o.__PAGE_GLM2 , source = data @ key , destination_key = key ,
@@ -340,8 +341,8 @@ h2o.glm <- function(x, y, data, key = "", family, link, nfolds = 0, alpha = 0.5,
340
341
lambda_search = as.numeric(lambda_search ), prior = prior ,
341
342
max_predictors = max_predictors , variable_importances = as.numeric(variable_importances ),
342
343
use_all_factor_levels = as.numeric(use_all_factor_levels ), link = link , offset = offset ,
343
- has_intercept = as.numeric(has_intercept ))
344
- } else
344
+ has_intercept = as.numeric(has_intercept ), non_negative = as.numeric( non_negative ) )
345
+ } else {
345
346
res = .h2o.__remoteSend(data @ h2o , .h2o.__PAGE_GLM2 , source = data @ key , destination_key = key ,
346
347
response = args $ y , ignored_cols = paste(x_ignore , sep = " " , collapse = " ," ), family = family ,
347
348
n_folds = nfolds , alpha = alpha , nlambdas = nlambda , lambda_min_ratio = lambda.min.ratio ,
@@ -350,24 +351,24 @@ h2o.glm <- function(x, y, data, key = "", family, link, nfolds = 0, alpha = 0.5,
350
351
lambda_search = as.numeric(lambda_search ),
351
352
max_predictors = max_predictors , variable_importances = as.numeric(variable_importances ),
352
353
use_all_factor_levels = as.numeric(use_all_factor_levels ), link = link , offset = offset ,
353
- has_intercept = as.numeric(has_intercept ))
354
+ has_intercept = as.numeric(has_intercept ), non_negative = as.numeric( non_negative )) }
354
355
355
356
params = list (x = args $ x , y = args $ y , family = .h2o.__getFamily(family , tweedie.var.p = tweedie.p ), nfolds = nfolds ,
356
357
alpha = alpha , nlambda = nlambda , lambda.min.ratio = lambda.min.ratio , lambda = lambda ,
357
358
beta_epsilon = epsilon , standardize = standardize , max_predictors = max_predictors ,
358
359
variable_importances = variable_importances , use_all_factor_levels = use_all_factor_levels , h2o = data @ h2o ,
359
- link = link , offset = offset , has_intercept = as.numeric(has_intercept ))
360
+ link = link , offset = offset , has_intercept = as.numeric(has_intercept ), non_negative = as.numeric( non_negative ) )
360
361
.h2o.__waitOnJob(data @ h2o , res $ job_key )
361
362
.h2o.get.glm(data @ h2o , as.character(res $ destination_key ), return_all_lambda )
362
363
} else
363
364
.h2o.glm2grid.internal(x_ignore , args $ y , data , key , family , link ,nfolds , alpha , nlambda , lambda.min.ratio , lambda , epsilon ,
364
365
standardize , prior , tweedie.p , iter.max , higher_accuracy , lambda_search , return_all_lambda ,
365
366
variable_importances = variable_importances , use_all_factor_levels = use_all_factor_levels ,
366
- offset = offset , has_intercept = as.numeric(has_intercept ))
367
+ offset = offset , has_intercept = as.numeric(has_intercept ), non_negative = as.numeric( non_negative ) )
367
368
}
368
369
369
370
.h2o.glm2grid.internal <- function (x_ignore , y , data , key , family , link , nfolds , alpha , nlambda , lambda.min.ratio , lambda , epsilon , standardize , prior , tweedie.p , iter.max , higher_accuracy , lambda_search , return_all_lambda ,
370
- variable_importances , use_all_factor_levels , offset , has_intercept ) {
371
+ variable_importances , use_all_factor_levels , offset , has_intercept , non_negative ) {
371
372
if (family == " tweedie" )
372
373
res = .h2o.__remoteSend(data @ h2o , .h2o.__PAGE_GLM2 , source = data @ key , destination_key = key , response = y ,
373
374
ignored_cols = paste(x_ignore , sep = " " , collapse = " ," ), family = family , n_folds = nfolds ,
@@ -376,7 +377,7 @@ h2o.glm <- function(x, y, data, key = "", family, link, nfolds = 0, alpha = 0.5,
376
377
higher_accuracy = as.numeric(higher_accuracy ), lambda_search = as.numeric(lambda_search ),
377
378
tweedie_variance_power = tweedie.p , variable_importances = as.numeric(variable_importances ),
378
379
use_all_factor_levels = as.numeric(use_all_factor_levels ), link = link , offset = offset ,
379
- has_intercept = as.numeric(has_intercept ))
380
+ has_intercept = as.numeric(has_intercept ), non_negative = as.numeric( non_negative ) )
380
381
else if (family == " binomial" ) {
381
382
if (missing(prior )) prior = - 1
382
383
res = .h2o.__remoteSend(data @ h2o , .h2o.__PAGE_GLM2 , source = data @ key , destination_key = key , response = y ,
@@ -385,7 +386,7 @@ h2o.glm <- function(x, y, data, key = "", family, link, nfolds = 0, alpha = 0.5,
385
386
beta_epsilon = epsilon , standardize = as.numeric(standardize ), max_iter = iter.max ,
386
387
higher_accuracy = as.numeric(higher_accuracy ), lambda_search = as.numeric(lambda_search ), prior = prior ,
387
388
variable_importances = as.numeric(variable_importances ), use_all_factor_levels = as.numeric(use_all_factor_levels ),
388
- link = link , offset = offset , has_intercept = as.numeric(has_intercept ))
389
+ link = link , offset = offset , has_intercept = as.numeric(has_intercept ), non_negative = as.numeric( non_negative ) )
389
390
}
390
391
else
391
392
res = .h2o.__remoteSend(data @ h2o , .h2o.__PAGE_GLM2 , source = data @ key , destination_key = key , response = y ,
@@ -394,13 +395,13 @@ h2o.glm <- function(x, y, data, key = "", family, link, nfolds = 0, alpha = 0.5,
394
395
beta_epsilon = epsilon , standardize = as.numeric(standardize ), max_iter = iter.max ,
395
396
higher_accuracy = as.numeric(higher_accuracy ), lambda_search = as.numeric(lambda_search ),
396
397
variable_importances = as.numeric(variable_importances ), use_all_factor_levels = as.numeric(use_all_factor_levels ),
397
- link = link , offset = offset , has_intercept = as.numeric(has_intercept ))
398
+ link = link , offset = offset , has_intercept = as.numeric(has_intercept ), non_negative = as.numeric( non_negative ) )
398
399
399
400
params = list (x = setdiff(colnames(data )[- (x_ignore + 1 )], y ), y = y , family = .h2o.__getFamily(family , tweedie.var.p = tweedie.p ),
400
401
link = link , nfolds = nfolds , alpha = alpha , nlambda = nlambda ,
401
402
lambda.min.ratio = lambda.min.ratio , lambda = lambda , beta_epsilon = epsilon , standardize = standardize ,
402
403
variable_importances = variable_importances , use_all_factor_levels = use_all_factor_levels , h2o = data @ h2o ,
403
- offset = offset , has_intercept = as.numeric(has_intercept ))
404
+ offset = offset , has_intercept = as.numeric(has_intercept ), non_negative = as.numeric( non_negative ) )
404
405
405
406
.h2o.__waitOnJob(data @ h2o , res $ job_key )
406
407
.h2o.get.glm.grid(data @ h2o , as.character(res $ destination_key ), return_all_lambda , data )
0 commit comments