Closed anitaschaefer closed 1 year ago
Hi Anita,
I belive that multiclass objectives require explicit multiclass code, that I didn't develop. Check out what the LGBM docs say regarding custom losses: https://lightgbm.readthedocs.io/en/latest/pythonapi/lightgbm.LGBMClassifier.html#lightgbm.LGBMClassifier
It looks like a multiclass LGBM model should already give you 2D preds, without you having to reshape them.
If you do add that feature, please let me know, I would be happy to add it to the package 🙂
@anitaschaefer Hi, I am also trying to deal with a problem to implement custom loss function for a multi-class classification problem with LightGBM. Do you have some further solution on this problem?
@Lydia-z yes, I opened an issue on the lightgbm repository as well, here is the response I got: https://github.com/microsoft/LightGBM/issues/5839#issuecomment-1515403394
I've adapted the hinge loss from the example to be usable for multiclass data. In essence, I've transformed targets into a one-hot matrix and reshaped preds to (n_samples, n_classes) to match the one-hot matrix:
I've used the iris dataset instead and trained the model as usual:
But the error doesn't decrease during training, instead looking like this: [1] training's multi_error: 1 training's multi_logloss: 34.5388 [2] training's multi_error: 1 training's multi_logloss: 34.5388 [3] training's multi_error: 1 training's multi_logloss: 34.5388 [4] training's multi_error: 1 training's multi_logloss: 34.5388 [5] training's multi_error: 1 training's multi_logloss: 34.5388 [6] training's multi_error: 1 training's multi_logloss: 34.5388 [7] training's multi_error: 1 training's multi_logloss: 34.5388 [8] training's multi_error: 1 training's multi_logloss: 34.5388 [9] training's multi_error: 1 training's multi_logloss: 34.5388 [10] training's multi_error: 1 training's multi_logloss: 34.5388
The binary example works just fine. What may be the cause of this?