modify script to use objective and eval_metric
This commit is contained in:
parent
27e4cbb215
commit
36031d9a36
@ -40,10 +40,10 @@ evalerror <- function(preds, dtrain) {
|
|||||||
return(list(metric = "error", value = err))
|
return(list(metric = "error", value = err))
|
||||||
}
|
}
|
||||||
|
|
||||||
param <- list(max.depth=2,eta=1,silent=1)
|
param <- list(max.depth=2,eta=1,silent=1,
|
||||||
|
objective = logregobj, eval_metric = evalerror)
|
||||||
# train with customized objective
|
# train with customized objective
|
||||||
xgb.cv(param, dtrain, nround, nfold = 5,
|
xgb.cv(param, dtrain, nround, nfold = 5)
|
||||||
obj = logregobj, feval=evalerror)
|
|
||||||
|
|
||||||
# do cross validation with prediction values for each fold
|
# do cross validation with prediction values for each fold
|
||||||
res <- xgb.cv(param, dtrain, nround, nfold=5, prediction = TRUE)
|
res <- xgb.cv(param, dtrain, nround, nfold=5, prediction = TRUE)
|
||||||
|
|||||||
@ -61,4 +61,5 @@ logregobjattr <- function(preds, dtrain) {
|
|||||||
print ('start training with user customized objective, with additional attributes in DMatrix')
|
print ('start training with user customized objective, with additional attributes in DMatrix')
|
||||||
# training with customized objective, we can also do step by step training
|
# training with customized objective, we can also do step by step training
|
||||||
# simply look at xgboost.py's implementation of train
|
# simply look at xgboost.py's implementation of train
|
||||||
bst <- xgb.train(param, dtrain, num_round, watchlist, logregobjattr, evalerror)
|
bst <- xgb.train(param, dtrain, num_round, watchlist,
|
||||||
|
objective=logregobj, eval_metric=evalerror)
|
||||||
|
|||||||
@ -31,9 +31,10 @@ evalerror <- function(preds, dtrain) {
|
|||||||
return(list(metric = "error", value = err))
|
return(list(metric = "error", value = err))
|
||||||
}
|
}
|
||||||
print ('start training with early Stopping setting')
|
print ('start training with early Stopping setting')
|
||||||
# training with customized objective, we can also do step by step training
|
|
||||||
# simply look at xgboost.py's implementation of train
|
bst <- xgb.train(param, dtrain, num_round, watchlist,
|
||||||
bst <- xgb.train(param, dtrain, num_round, watchlist, logregobj, evalerror, maximize = FALSE,
|
objective = logregobj, eval_metric = evalerror, maximize = FALSE,
|
||||||
early.stop.round = 3)
|
early.stop.round = 3)
|
||||||
bst <- xgb.cv(param, dtrain, num_round, nfold=5, obj=logregobj, feval = evalerror,
|
bst <- xgb.cv(param, dtrain, num_round, nfold = 5,
|
||||||
|
objective = logregobj, eval_metric = evalerror,
|
||||||
maximize = FALSE, early.stop.round = 3)
|
maximize = FALSE, early.stop.round = 3)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user