我想估计具有预定义的最大活动预测变量数的h2o.glm模型(非默认的max_active_predictors列)。这是一个例子:
set.seed(123)
par1 <- matrix(c(100, 200, 300, 400, 40, 30, 20, 10), 4, 2)
par2 <- c(1000, 2000, 3000, 4000)
coef <- c(0.5, -0.5, 1, -1, 1.5, -1.5, 2, -2)
mat <- as.data.frame(cbind(apply(par1, 1, function(x) rnorm(1000, mean = x[1], sd = x[2])),
sapply(par2, function(x) rpois(1000, lambda = x))))
mat$Y <- as.numeric(t(coef %*% t(mat)))
h2o.init(nthreads = -1)
mat_h2o <- as.h2o(mat, "mat.h2o")
glm_base <- h2o.glm(x = setdiff(colnames(mat), "Y"),
y = "Y",
training_frame = mat_h2o,
solver = "IRLSM",
family = "gaussian",
link = "family_default",
alpha = 1,
lambda_search = TRUE,
nlambdas = 10)
summary(glm_base)
glm_restr <- h2o.glm(x = setdiff(colnames(mat), "Y"),
y = "Y",
training_frame = mat_h2o,
solver = "IRLSM",
family = "gaussian",
link = "family_default",
alpha = 1,
lambda_search = TRUE,
nlambdas = 10,
max_active_predictors = 3)
summary(glm_restr)
来自glm_base的摘要看起来与我的感觉完全相同(八个非零预测变量),但后者是反直觉的(也是八个非零预测变量)。我如何强制算法将最终模型的复杂性限制为预定义数量的变量。
答案 0 :(得分:1)
我认为这是一个错误。 (已确认,请参阅https://0xdata.atlassian.net/browse/PUBDEV-3455)
当我h2o.scoreHistory(glm_restr)
时,我得到了:
Scoring History:
timestamp duration iteration lambda predictors deviance_train
1 2016-09-21 09:25:29 0.000 sec 0 .46E2 4 9806.688
2 2016-09-21 09:25:29 0.052 sec 0 .17E2 7 1988.941
3 2016-09-21 09:25:29 0.100 sec 0 .6E1 9 294.884
4 2016-09-21 09:25:29 0.153 sec 0 .21E1 9 38.086
5 2016-09-21 09:25:29 0.203 sec 0 .77E0 9 4.919
6 2016-09-21 09:25:29 0.255 sec 0 .28E0 9 0.635
7 2016-09-21 09:25:30 0.307 sec 0 .1E0 9 0.082
8 2016-09-21 09:25:30 0.358 sec 0 .36E-1 9 0.011
9 2016-09-21 09:25:30 0.408 sec 0 .13E-1 9 0.001
即。 lambda值为46的lambda搜索的第一次迭代似乎已经超过3并且直接变为4。
有了这个线索,我可以通过跳过lambda搜索并选择一个50的lambda来获得三个预测器:
glm_L50 <- h2o.glm(x = setdiff(colnames(mat), "Y"),
y = "Y",
training_frame = mat_h2o,
solver = "IRLSM",
family = "gaussian",
link = "family_default",
alpha = 1,
lambda = 50)
输出glm_L50
说:
GLM Model: summary
family link regularization number_of_predictors_total
1 gaussian identity Lasso (lambda = 50.0 ) 8
number_of_active_predictors number_of_iterations training_frame
1 3 0 mat.h2o
Coefficients: glm coefficients
names coefficients standardized_coefficients
1 Intercept -998.311697 -3657.657068
2 V1 0.000000 0.000000
3 V2 0.000000 0.000000
4 V3 0.000000 0.000000
5 V4 0.000000 0.000000
6 V5 0.000000 0.000000
7 V6 -0.389528 -17.453935
8 V7 1.014556 53.969163
9 V8 -1.229969 -81.328717
H2ORegressionMetrics: glm
** Reported on training data. **
MSE: 10921.23
RMSE: 104.5047
MAE: 83.98198
RMSLE: NaN
Mean Residual Deviance : 10921.23
R^2 : 0.6932398
Null Deviance :35601860
Null D.o.F. :999
Residual Deviance :10921233
Residual D.o.F. :996
AIC :12146.34