1

I need to implement a custom loss function.

The function is relatively simple:

$$-\sum \limits_{i=1}^m [O_{1,i} \cdot y_i-1] \ \cdot \ \operatorname{ReLu}(O_{1,i} \cdot \hat{y_i} - 1)$$

With $O$ being some external attribute specific to each case.

I was initially working with LightGBM, but I only found tutorials that included calculating the hessian and the gradient. If there is a way to add the function without this please correct me.

Otherwise I am open to using other libraries. PyTorch-Fastai, Tensorflow-keras, catboost, etc. would all be fine.

Eventually, I would like to get my hands dirty with the math, but first I would like to run the model.

Borut Flis
  • 189
  • 1
  • 7
  • 2
    Checkout this https://keras.io/api/losses/#creating-custom-losses. It might be a nuisance to get the $O_{1,i}$ into your loss function, though. – Maximilian Janisch Jul 21 '21 at 17:27
  • 2
    With xgboost you need to add hessian & gradient but otherwise the implementation ist relatively simple https://datascience.stackexchange.com/questions/81447/xgboost-custom-objective-for-regression-in-r – Peter Jul 21 '21 at 19:49

0 Answers0