Nicolas
Nicolas

Reputation: 399

fit_params doesn't work with XGBoost and Scikit-learn MultiOutputRegressor

I would like to use MultiOutputRegressor from scikit-learn to train a XGB on a multi output regression problem. But I can't pass a fit_params dictionary to the .fit method of a MultiOutputRegressor. It looks like it doesn't recognize the parameters inside...

I receive this error:

from sklearn.multioutput import MultiOutputRegressor
from xgboost.sklearn import XGBRegressor
XGB = XGBRegressor(n_jobs=1, max_depth=10, n_estimators=100, learning_rate=0.2)  
fit_params = {'early_stopping_rounds':5,
                'eval_set':[(X_holdout,Y_holdout)],
                'eval_metric':'mae',
                'verbose':False}
multi = MultiOutputRegressor(XGB, n_jobs=-1)    
multi.fit(X_train,Y_train,**fit_params) 

Traceback (most recent call last):

  File "<ipython-input-16-e245db56e1be>", line 9, in <module>
    multi.fit(X_train,Y_train,**fit_params)

TypeError: fit() got an unexpected keyword argument 'early_stopping_rounds'

What is strange is that it works with RandomizedSearchCV

from sklearn.model_selection import RandomizedSearchCV
XGB_cv = RandomizedSearchCV(XGB, params, cv=5, n_jobs=-1, verbose=1, n_iter=1000, scoring='neg_mean_absolute_error')  
XGB_cv.fit(X_train, Y_train,**fit_params)  

Upvotes: 1

Views: 832

Answers (1)

Eduard Ilyasov
Eduard Ilyasov

Reputation: 3308

It seems that you have installed scikit-learn package version where **fit_params param of fit method is not implemented for MultiOutputRegressor. You can check version of installed package by using following commands:

import sklearn
print(sklearn.__version__)

After upgrading scikit-learn package to version 0.23.1 you can use **fit_params in fit method of MultiOutputRegressor object. You can upgrade it using this way:

pip install --upgrade scikit-learn

Upvotes: 2

Related Questions