在使用sklearn.model_selection的cross_val_score实现交叉验证时,我们也希望在fit时加入一些控制参数(比如sample_weight, eval_set, eval_metric, early_stopping_rounds等),以提高训练效率。
具体的实现方法就是在cross_val_score的fit_params中指定对应参数:
fit_params : dict, optional
Parameters to pass to the fit method of the estimator.
然后estimator将在调用fit方法时传入这些参数:
try:
if y_train is None:
estimator.fit(X_train, **fit_params)
else:
estimator.fit(X_train, y_train, **fit_params)