Ich bin neu in xgboost
und versuche zu lernen, wie man es verwendet, indem man es mit dem traditionellen gbm
vergleicht. Allerdings habe ich festgestellt, dass xgboost
ist viel viel langsamer als gbm
. Das Beispiel ist:XGBRegressor viel langsamer als GradientBoostingRegressor
from sklearn.model_selection import KFold, GridSearchCV
from sklearn.ensemble import GradientBoostingRegressor
from xgboost import XGBRegressor
from sklearn.datasets import load_boston
import time
boston = load_boston()
X = boston.data
y = boston.target
kf = KFold(n_splits = 5)
cv_params = {'cv': kf, 'scoring': 'r2', 'n_jobs': 4, 'verbose': 1}
gbm = GradientBoostingRegressor()
xgb = XGBRegressor()
grid = {'n_estimators': [100, 300, 500], 'max_depth': [3, 5]}
timer = time.time()
gbm_cv = GridSearchCV(gbm, param_grid = grid, **cv_params).fit(X, y)
print('GBM time: ', time.time() - timer)
timer = time.time()
xgb_cv = GridSearchCV(xgb, param_grid = grid, **cv_params).fit(X, y)
print('XGB time: ', time.time() - timer)
auf einem MacBook Pro mit 8 Kernen, der Ausgang ist:
Fitting 5 folds for each of 6 candidates, totalling 30 fits
[Parallel(n_jobs=4)]: Done 30 out of 30 | elapsed: 1.9s finished
GBM time: 2.262791872024536
Fitting 5 folds for each of 6 candidates, totalling 30 fits
[Parallel(n_jobs=4)]: Done 30 out of 30 | elapsed: 16.4s finished
XGB time: 17.902266025543213
Ich dachte xgboost sollte viel schneller sein, so muss ich etwas falsch machen. Kann jemand helfen, aufzuzeigen, was ich falsch mache?
Das ist, was ich Ihren Code genau ausgeführt habe: 'GBM-Zeit: 2.1901206970214844 XGB-Zeit: 2.5632455348968506'. – josh