-
Notifications
You must be signed in to change notification settings - Fork 2k
Description
{code:java}
prostate.hex <- h2o.importFile("/Users/nidhimehta/h2o-3/smalldata/logreg/prostate.csv")
myX <- c("AGE","RACE", "DPROS", "DCAPS", "PSA", "VOL", "GLEASON")
myY <- "CAPSULE"
(my_glm <- h2o.glm(x = myX, y = myY, training_frame = prostate.hex, family = "binomial",))
lowerbound <- rep(-7, times = length(myX))
upperbound <- rep(.5, times = length(myX))
colnames <- my_glm@model$coefficients_table$names[my_glm@model$coefficients_table$names != "Intercept"]
betaConstraints <- data.frame(names = colnames, lower_bounds = lowerbound, upper_bounds = upperbound)
betaConstraints.hex <- as.h2o(betaConstraints, destination_frame = "betaConstraints.hex")
prostate.r <- as.data.frame(prostate.hex)
prior = .1
r1 = length(which(prostate.r$CAPSULE==1))/nrow(prostate.r)
w1=prior/r1;
w2=(1-prior)/(1-r1);
prostate.hex$weight = ifelse(prostate.hex$CAPSULE==1, w1,w2)
(glm_constraints.h2o <- h2o.glm(x = myX, y = myY, training_frame = prostate.hex, standardize = TRUE,weights_column = "weight",
family = "binomial", alpha = .5 , beta_constraint = betaConstraints.hex,
lambda = 1e-05))
prostate.r$weight = ifelse(prostate.r$CAPSULE==1,yes = w1,no = w2)
glm_constraints.r <- glmnet(x = as.matrix(prostate.r[,myX]), alpha = .5, lambda = 1e-05,weights = prostate.r$weight,
standardize = TRUE, y = prostate.r[,myY], family = "binomial",
lower.limits = lowerbound, upper.limits = upperbound,intercept=TRUE)
glm_constraints.r$beta
#7 x 1 sparse Matrix of class "dgCMatrix"
s0
#AGE -0.01078026
#RACE -0.91688877
#DPROS 0.47187809
#DCAPS 0.50000000
#PSA 0.03394019
#VOL -0.01495315
#GLEASON 0.50000000
glm_constraints.r$a0
#-5.578778
glm_constraints.h2o@model$coefficients_table
#Coefficients: glm coefficients
names coefficients standardized_coefficients
#1 Intercept -2.197225 -2.197225
#2 AGE 0.000000 0.000000
#3 RACE 0.000000 0.000000
#4 DPROS 0.000000 0.000000
#5 DCAPS 0.000000 0.000000
#6 PSA 0.000000 0.000000
#7 VOL 0.000000 0.000000
#8 GLEASON 0.000000 0.000000
{code}