I use xgboost.XGBClassifier for a multiclass classification problem, and I want to adjust the algorithm such way as to make the metric
f1_score(average='macro') higher. I tried changing a parameter
objective of XGBClassifier and made the following:
from sklearn.metrics import f1_score def f1_macro(y_true, y_pred): return f1_score(y_true, y_pred, average='macro') xg_tree = xgb.XGBClassifier(max_depth = 3, n_estimators = 1000, booster = 'gbtree', n_jobs=-1, subsample=1, learning_rate=0.005, objective = f1_macro, num_cass = 3) xg_tree.fit(X_train, y_train)
But I have a mistake
ValueError: Classification metrics can't handle a mix of multiclass and continuous-multioutput targets
As I've read the custom objective function should output the value of a gradient and a hessian.
Could you please help me to figure out what way I should rewrite my objective function to fix this mistake?
Thanks in advance!