如果我使用以下代码训练模型:
import xgboost as xg
params = {'max_depth':3,
'min_child_weight':10,
'learning_rate':0.3,
'subsample':0.5,
'colsample_bytree':0.6,
'obj':'reg:linear',
'n_estimators':1000,
'eta':0.3}
features = df[feature_columns]
target = df[target_columns]
dmatrix = xg.DMatrix(features.values,
target.values,
feature_names=features.columns.values)
clf = xg.train(params, dmatrix)
它会在大约1分钟内完成。
如果我使用Sci-Kit学习方法训练模型:
import xgboost as xg
max_depth = 3
min_child_weight = 10
subsample = 0.5
colsample_bytree = 0.6
objective = 'reg:linear'
num_estimators = 1000
learning_rate = 0.3
features = df[feature_columns]
target = df[target_columns]
clf = xg.XGBRegressor(max_depth=max_depth,
min_child_weight=min_child_weight,
subsample=subsample,
colsample_bytree=colsample_bytree,
objective=objective,
n_estimators=num_estimators,
learning_rate=learning_rate)
clf.fit(features, target)
需要30分钟以上。
我认为底层代码几乎完全相同(即XGBRegressor
调用xg.train
)-这是怎么回事?