当我使用 XGBoost 拟合模型时,它通常会显示一系列消息,例如“updater_prune.cc:74: tree pruning end, 1 个 root, 6 extra nodes, 0 pruned nodes, max_depth=5”。我想知道 XGBoost 是如何进行树修剪的?我在他们的论文中找不到关于他们修剪过程的描述。
注意:我确实了解决策树修剪过程,例如预修剪和后修剪。这里我很好奇XGBoost的实际剪枝过程。通常修剪需要验证数据,但即使我没有给它任何验证数据,XGBoost 也会执行修剪。
我正在使用修改后的Forecast.py来测试修剪的SqueezeNet模型
[phung@archlinux SqueezeNet-Pruning]$ python predict.py --image 3_100.jpg --model model_prunned --num_class 2
prediction in progress
Traceback (most recent call last):
File “predict.py”, line 66, in
prediction = predict_image(imagepath)
File “predict.py”, line 52, in predict_image
index = output.data.numpy().argmax()
TypeError: can’t convert CUDA tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.
[phung@archlinux SqueezeNet-Pruning]$
Run Code Online (Sandbox Code Playgroud)
我了解numpy还不支持gpu。
如何在不调用张量复制数据操作Tensor.cpu()的情况下修改代码以摆脱此错误?
我正在用Java创建一个Flyweight,我想确保我不会创建太大的地图.是否有更有效的方法来修剪地图?我没有看到任何可以自动执行此操作的属性(如max size构造函数),所以我在代码中执行此操作.
这是我拥有的,非常基本的,但我想确保没有更好的方法:
private static void prune() {
Iterator<Entry<Integer, Integer[]>> iterator = seeds.entrySet().iterator();
int removed = 0;
while(iterator.hasNext()|| removed == pruneLength) {
iterator.next();
iterator.remove();
removed++;
}
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试删除所有合并的分支.我一直都在用
git branch --merged | egrep -v "(^\*|master|dev)" | xargs git branch -d但由于某种原因,它不再适用,即使我之前使用过这个命令.它返回错误"致命:需要分支名称"
有没有办法用 CatBoost 和 Optuna 进行修剪(在 LightGBM 中很容易,但在 Catboost 中我找不到任何提示)。我的代码是这样的
def objective(trial):
param = {
'iterations':trial.suggest_int('iterations', 100,1500, step=100),
'learning_rate':trial.suggest_uniform("learning_rate", 0.001, 0.3),
'random_strength':trial.suggest_int("random_strength", 1,10),
'max_bin':trial.suggest_categorical('max_bin', [2,3,4,5,6,8,10,20,30]),
'grow_policy':trial.suggest_categorical('grow_policy', ['SymmetricTree', 'Depthwise', 'Lossguide']),
"colsample_bylevel": trial.suggest_uniform("colsample_bylevel", 0.1, 1),
'od_type' : "Iter",
'od_wait' : 30,
"depth": trial.suggest_int("max_depth", 1,12),
"l2_leaf_reg": trial.suggest_loguniform("l2_leaf_reg", 1e-8, 100),
'custom_metric' : ['AUC'],
"loss_function": "Logloss",
}
if param['grow_policy'] == "SymmetricTree":
param["boosting_type"]= trial.suggest_categorical("boosting_type", ["Ordered", "Plain"])
else:
param["boosting_type"] = "Plain"
# Added subsample manually
param["subsample"] = trial.suggest_float("subsample", 0.1, 1)
### CV ###
# How to add a …Run Code Online (Sandbox Code Playgroud)