New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error using loss and custom metric #9782
Comments
Hi, due to limitations in the existing implementation, when a custom metric is used, no additional metric names is allowed. However, feel free to remove the xgb.XGBClassifier(eval_metric=fbeta_score) assuming the |
Hi @trivialfis , Could you help clarify below suggestion ?
If I want to track both
Thank you so much! |
Unfortunately, XGBoost doesn't work with composite metrics. However, you can use the logloss inside XGBoost along with the fbeta score: import numpy as np
import xgboost as xgb
from sklearn.datasets import load_digits
from sklearn.metrics import fbeta_score
X, y = load_digits(n_class=2, return_X_y=True)
def error(y_true, y_pred, *args, **kwargs) -> float:
classes = np.repeat(0, y_pred.shape[0])
classes[y_pred > 0.5] = 1
y_pred = classes
return -fbeta_score(y_true, y_pred, *args, **kwargs, beta=1.0)
clf = xgb.XGBClassifier(eval_metric=error)
clf.fit(X, y, eval_set=[(X, y)])
|
In case anyone using XGBoost native API , not sklearn API, here is the example:
|
Problem
I have a binary classification task with a highly imbalanced dataset. Therefore, i want to use the logloss in combination with a custom function (fbeta score) as scoring metric. However, i get the error (Unknown metric function <function Classifier.xgb_custom_fbeta_score at 0x0000015F662DADD0>) for the following implementation.
If i use only the custom metric it works but then i can not track the logloss during training and validation.
Implementation
The text was updated successfully, but these errors were encountered: