我正在尝试使用sink
函数保存增强日志,如下代码所示:
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()
但是我看不到“发生了什么”,因为它没有打印函数的输出和/或消息。
我的问题是如何检索.txt
sink
文件,并查看该功能(在本例中为xgb.cv
)是否正在打印?
谢谢!
答案 0 :(得分:6)
使用参数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()
如上所示,它将在控制台上打印,您还可以在当前目录中找到test.txt
文件。