I am trying to save the log of a boosting using sink
function, as following code:
require(xgboost)
require(R.utils)
data(iris)
train.model <- model.matrix(Sepal.Length~., iris)
dtrain <- xgb.DMatrix(data=train.model, label=iris$Sepal.Length)
xgb_grid = list(eta = 0.05, max_depth = 5, subsample = 0.7, gamma = 0.3,
min_child_weight = 1)
sink("evaluationLog.txt")
fit_boost <-xgb.cv(data = dtrain,
nrounds = 1000,
objective = "reg:linear",
eval_metric = "logloss",
params = xgb_grid,
colsample_bytree = 0.7,
early_stopping_rounds = 100,
nfold = 5,
prediction = TRUE,
maximize = FALSE
)
sink()
However I can't see "what's happening" since it's not printing the function's output and/or message.
My question is how can I can retrieve both a .txt
file with sink
and see what the function (in this case would be xgb.cv
) is printing?
Thank you!
Use argument split
:
sink('test.txt', split = TRUE)
print(letters)
# [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q"
#[18] "r" "s" "t" "u" "v" "w" "x" "y" "z"
sink()
As you can see above it will both print on the console and you will also find a test.txt
file in your current directory.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With