I am trying to use XGBoost and optimize eval_metrichow auc(as described here ).
This works fine when using the classifier directly, but fails when I try to use it as a pipeline .
What is the correct way to pass an argument .fitto the sklearn pipeline?
Example:
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.datasets import load_iris
from xgboost import XGBClassifier
import xgboost
import sklearn
print('sklearn version: %s' % sklearn.__version__)
print('xgboost version: %s' % xgboost.__version__)
X, y = load_iris(return_X_y=True)
xgb = XGBClassifier()
xgb.fit(X, y, eval_metric='auc')
pipe = Pipeline([('scaler', StandardScaler()), ('classifier', XGBClassifier())])
pipe.fit(X, y)
pipe.fit(X, y, classifier__eval_metric='auc')
Error:
TypeError: before_fit() got an unexpected keyword argument 'classifier__eval_metric'
As for the xgboost version:
xgboost.__version__shows 0.6
pip3 freeze | grep xgboostshows xgboost==0.6a2.
source
share