[英]How to choose the nrounds using `catboost`?
如果我理解正確catboost
,我們需要像在xgboost
一樣使用 CV 調整nrounds
。 我在官方教程中看到如下代碼在[8]
params_with_od <- list(iterations = 500,
loss_function = 'Logloss',
train_dir = 'train_dir',
od_type = 'Iter',
od_wait = 30)
model_with_od <- catboost.train(train_pool, test_pool, params_with_od)
這導致最佳iterations
= 211。
我的問題是:
test_pool
來選擇最佳iterations
而不是使用交叉驗證?iterations
的命令,還是我需要手動執行?Catboost 正在進行交叉驗證以確定最佳迭代次數。 train_pool 和 test_pool 都是包含目標變量的數據集。 在本教程的早些時候,他們寫了
train_path = '../R-package/inst/extdata/adult_train.1000'
test_path = '../R-package/inst/extdata/adult_test.1000'
column_description_vector = rep('numeric', 15)
cat_features <- c(3, 5, 7, 8, 9, 10, 11, 15)
for (i in cat_features)
column_description_vector[i] <- 'factor'
train <- read.table(train_path, head=F, sep="\t", colClasses=column_description_vector)
test <- read.table(test_path, head=F, sep="\t", colClasses=column_description_vector)
target <- c(1)
train_pool <- catboost.from_data_frame(data=train[,-target], target=train[,target])
test_pool <- catboost.from_data_frame(data=test[,-target], target=test[,target])
當您執行 catboost.train(train_pool, test_pool, params_with_od) train_pool 用於訓練時, test_pool 用於通過交叉驗證確定最佳迭代次數。
現在您感到困惑是正確的,因為在本教程的后面,他們再次使用 test_pool 和擬合模型進行預測(model_best 類似於 model_with_od,但使用不同的過擬合檢測器 IncToDec):
prediction_best <- catboost.predict(model_best, test_pool, type = 'Probability')
這可能是不好的做法。 現在他們可能會用他們的 IncToDec 過擬合檢測器逃脫它 - 我不熟悉它背后的數學 - 但是對於 Iter 類型的過擬合檢測器,您需要有單獨的訓練、驗證和測試數據集(如果你想成為在保存方面,對 IncToDec 過擬合檢測器執行相同的操作)。 然而,這只是一個展示功能的教程,所以我不會對他們已經如何使用哪些數據過於迂腐。
這里有一個關於過擬合檢測器的更多細節的鏈接: https : //tech.yandex.com/catboost/doc/dg/concepts/overfit-detector-docpage/
使用插入符交叉驗證。 注意本教程的 [12] 。
library(catboost)
library(data.table)
parameter = list(
thread_count = n_cores,
loss_function = "RMSE",
eval_metric = c("RMSE","MAE","R2"),
iterations = 10^5, # Train up to 10^5 rounds
early_stopping_rounds = 100, # Stop after 100 rounds of no improvement
)
# Apply 6-fold CV
model = catboost.cv(
pool = train_pool,
fold_count = 6,
params = parameter
)
# Transform output to DT
setDT(cbt_occupancy)
model[, iterations := .I]
# Order from lowest to highgest RMSE
setorder(model, test.RMSE.mean)
# Select iterations with lowest RMSE
parameter$iterations = model[1, iterations]
# Train model with optimal iterations
model = catboost.train(
learn_pool = train_pool,
test_pool = test_pool,
params = parameter
)
我認為這是 xgboost 和 catboost 的一般問題。 nround
的選擇與學習率的選擇有關。 因此,我推薦更高的回合(1000+)和低學習率。 在找到最佳炒作參數並重試較低的學習率以檢查您選擇的炒作參數是否穩定后。
我發現@nikitxskv 的回答具有誤導性。
learning_rate = 0.1
沒有多重選擇。 因此,沒有關於nround
調整的提示。expand.grid
來找到最好的炒作參數。 它對depth
、 gamma
等的選擇起作用。nround
(太長)。現在來回答兩個問題。
是否正確:此命令使用 test_pool 來選擇最佳迭代而不是使用交叉驗證?
是的,但您可以使用 CV。
如果是,catboost 是否提供了從 CV 中選擇最佳迭代的命令,還是我需要手動執行?
這取決於你自己。 如果您非常厭惡提升過度擬合,我建議您嘗試一下。 有很多包可以解決這個問題。 我推薦tidymodel
包。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.