catboost icon indicating copy to clipboard operation
catboost copied to clipboard

CatBoost is about 5 times slower than LightGBM?

Open littlebeandog opened this issue 7 years ago • 8 comments

There's already some issues talking about that catboost is slower than lgb. I've followed the suggestion to tune hyper params, but I still cant make catboost reach the same performance as lightgbm, both on speed and loss. I've run both model 10000 iterations on same machine and same dataset, it takes 6m 11s for catboost and 1min20s for lgb. Also the MAE loss on valid set is 0.38(cat) vs 0.32(lgb).

How could I make catboost run as fast as lgb, also reach the same performace? Also I've tried to run catboost on GPU(P40), and It takes (1min 10s) just as fast as lightgbm on cpu.

CPU: E5-2630 Here's the hyper params:

  • CatBoost
params={
    'eval_metric': 'MAE',
    'loss_function': 'RMSE',
    'task_type': 'CPU',
    'learning_rate': 0.01,
    'grow_policy': 'SymmetricTree',
    'boosting_type': 'Plain',
    'depth': 9,
    'leaf_estimation_iterations':1
}
  • LightGBM
params = {
    'num_leaves': 84,
    'min_child_samples': 22,
    'objective': 'regression',
    'max_depth': 9,
    'learning_rate': 0.01,
    "boosting_type": "gbdt",
    "subsample_freq": 1,
    "subsample": 0.8,
    "bagging_seed": 42,
    "metric": 'mae',
    "verbosity": -1,
    'reg_alpha': 1,
    'reg_lambda': 3,
    'colsample_bytree': 0.8
}

littlebeandog avatar Jul 17 '19 04:07 littlebeandog

The speed issue probably comes from having depth 9 for catboost and bulding full binary tree with 2^9 leaves and depth 9+num_leaves=84 for LightGBm, which will build much smaller tree. To have same leaf count tree in LightGBM, which will provide same amount of calculations as in CatBoost, you need to set num_leaves = 2^9 in LightGBM and not set depth to 9.

Another reason is colsample_bytree 0.8 which gives a 20% speedup, you can set the same in catboost (rsm = 0.8) and have the same 20% speedup.

As for MAE value - if you would provide us with your data, it would be easier to debug. But firstly, check that the training has converged, so that the validation loss stopped improving, otherwise increase learning rate or number of iterations. Secondly, if there is big difference, that might mean that you need not symmetric trees. It happens usually in case if the data is simulated, if it has little amount of noise, or if it has one-hot encoding or is sparse. To check if you need not symmetric trees, set grow_polycy='Lossguide' on GPU.

annaveronika avatar Jul 17 '19 08:07 annaveronika

@littlebeandog Is it possible to share the dataset?

annaveronika avatar Jul 17 '19 08:07 annaveronika

Sorry, I have read it wrong, P40 is a pretty new GPU, I was thinking you are using K40. With P40 the speedup should be 10 to 15 times for large datasets, as in your case.

annaveronika avatar Jul 17 '19 12:07 annaveronika

I've estimated performance on same dataset again for n_estimator=10000. The result is here.

model time used mae
catboost 188.7s 0.34
lightgbm 96.7s 0.32

hyperparams:

  • lgb
params = {
    'num_leaves': 84,
    'min_child_samples': 22,
    'objective': 'regression',
    'max_depth': 9,
    'learning_rate': 0.05,
    "boosting_type": "gbdt",
    "subsample_freq": 1,
    "subsample": 0.8,
    "bagging_seed": 42,
    "metric": 'mae',
    "verbosity": -1,
    'reg_alpha': 1,
    'reg_lambda': 3,
    'colsample_bytree': 0.8
}
  • cat
params={
    'eval_metric': 'MAE',
    'loss_function': 'RMSE',
    'task_type': 'CPU',
    'learning_rate': 0.05,
    'boosting_type': 'Plain',
    'depth': 6,
    'bootstrap_type': 'Bernoulli',
    'subsample': 0.8,
    'rsm': 0.8
}

I think with these hyper params, both models should have similar splits. Maybe catboost is in a little advantage with 64 leaves while lightgbm is 84, also with 128 max bins while lightgbm is 255.

As for the speed, lightgbm is about twice faster than catboost. As for quality, I found a strange phenomenon that catboost always pick the same feature in the last level of each tree, which I think wont make sense to gain much information. Is that how symmetry growing policy work? I've attached graph of first tree structure of both model. Please let me know if you got any further Idea about why is this happenning, or anything I've missed, thanks. cat_tree_0.gv.pdf lgb_tree_0.gv.pdf

littlebeandog avatar Jul 18 '19 04:07 littlebeandog

@littlebeandog how did you generate those tree images?

david-waterworth avatar Jul 30 '19 04:07 david-waterworth

@littlebeandog how did you generate those tree images?

Use plot_tree api. You may meet with decoding bug, just delete the line in source code

littlebeandog avatar Jul 30 '19 08:07 littlebeandog

@littlebeandog We've made some major speedups last year, could you rerun comparison on Catboost 0.24 if it's possible?

kizill avatar Aug 05 '20 11:08 kizill

Closing for inactivity.

kizill avatar Feb 01 '21 20:02 kizill