Skip to content

Commit 0b96923

Browse files
committed
set trees
1 parent 3ed7fd3 commit 0b96923

File tree

6 files changed

+44
-8
lines changed

6 files changed

+44
-8
lines changed

Encoding/Example.Rmd

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,20 @@ crossValPlan <- vtreat::kWayStratifiedY(nrow(titanic_train),
4848
evaluateModelingProcedure <- function(xMatrix, outcomeV, crossValPlan) {
4949
preds <- rep(NA_real_, nrow(xMatrix))
5050
for(ci in crossValPlan) {
51-
model <- xgboost(data= xMatrix[ci$train, ],
51+
nrounds <- 1000
52+
cv <- xgb.cv(data= xMatrix[ci$train, ],
5253
label= outcomeV[ci$train],
5354
objective= 'binary:logistic',
54-
nrounds= 1000,
55-
verbose= 0)
55+
nrounds= nrounds,
56+
verbose= 0,
57+
nfold= 5)
58+
#nrounds <- which.min(cv$evaluation_log$test_rmse_mean) # regression
59+
nrounds <- which.min(cv$evaluation_log$test_error_mean) # classification
60+
model <- xgboost(data= xMatrix[ci$train, ],
61+
label= outcomeV[ci$train],
62+
objective= 'binary:logistic',
63+
nrounds= nrounds,
64+
verbose= 0)
5665
preds[ci$app] <- predict(model, xMatrix[ci$app, ])
5766
}
5867
preds
@@ -143,10 +152,19 @@ for(ci in crossValPlan) {
143152
sf <- tplan$scoreFrame
144153
newvars <- sf$varName[sf$sig < 1/nrow(sf)]
145154
trainVtreat <- cfe$crossFrame[ , c(newvars, outcome), drop=FALSE]
155+
nrounds <- 1000
156+
cv <- xgb.cv(data= as.matrix(trainVtreat[, newvars, drop=FALSE]),
157+
label= trainVtreat[[outcome]]==1,
158+
objective= 'binary:logistic',
159+
nrounds= nrounds,
160+
verbose= 0,
161+
nfold= 5)
162+
#nrounds <- which.min(cv$evaluation_log$test_rmse_mean) # regression
163+
nrounds <- which.min(cv$evaluation_log$test_error_mean) # classification
146164
model <- xgboost(data= as.matrix(trainVtreat[, newvars, drop=FALSE]),
147165
label= trainVtreat[[outcome]]==1,
148166
objective= 'binary:logistic',
149-
nrounds= 1000,
167+
nrounds= nrounds,
150168
verbose= 0)
151169
appVtreat <- vtreat::prepare(tplan,
152170
titanic_train[ci$app, , drop=FALSE],

Encoding/Example.md

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,20 @@ crossValPlan <- vtreat::kWayStratifiedY(nrow(titanic_train),
103103
evaluateModelingProcedure <- function(xMatrix, outcomeV, crossValPlan) {
104104
preds <- rep(NA_real_, nrow(xMatrix))
105105
for(ci in crossValPlan) {
106-
model <- xgboost(data= xMatrix[ci$train, ],
106+
nrounds <- 1000
107+
cv <- xgb.cv(data= xMatrix[ci$train, ],
107108
label= outcomeV[ci$train],
108109
objective= 'binary:logistic',
109-
nrounds= 1000,
110-
verbose= 0)
110+
nrounds= nrounds,
111+
verbose= 0,
112+
nfold= 5)
113+
#nrounds <- which.min(cv$evaluation_log$test_rmse_mean) # regression
114+
nrounds <- which.min(cv$evaluation_log$test_error_mean) # classification
115+
model <- xgboost(data= xMatrix[ci$train, ],
116+
label= outcomeV[ci$train],
117+
objective= 'binary:logistic',
118+
nrounds= nrounds,
119+
verbose= 0)
111120
preds[ci$app] <- predict(model, xMatrix[ci$app, ])
112121
}
113122
preds
@@ -249,10 +258,19 @@ for(ci in crossValPlan) {
249258
sf <- tplan$scoreFrame
250259
newvars <- sf$varName[sf$sig < 1/nrow(sf)]
251260
trainVtreat <- cfe$crossFrame[ , c(newvars, outcome), drop=FALSE]
261+
nrounds <- 1000
262+
cv <- xgb.cv(data= as.matrix(trainVtreat[, newvars, drop=FALSE]),
263+
label= trainVtreat[[outcome]]==1,
264+
objective= 'binary:logistic',
265+
nrounds= nrounds,
266+
verbose= 0,
267+
nfold= 5)
268+
#nrounds <- which.min(cv$evaluation_log$test_rmse_mean) # regression
269+
nrounds <- which.min(cv$evaluation_log$test_error_mean) # classification
252270
model <- xgboost(data= as.matrix(trainVtreat[, newvars, drop=FALSE]),
253271
label= trainVtreat[[outcome]]==1,
254272
objective= 'binary:logistic',
255-
nrounds= 1000,
273+
nrounds= nrounds,
256274
verbose= 0)
257275
appVtreat <- vtreat::prepare(tplan,
258276
titanic_train[ci$app, , drop=FALSE],
1.42 KB
Loading
623 Bytes
Loading
894 Bytes
Loading
1.84 KB
Loading

0 commit comments

Comments
 (0)