Differentiable Spearman Correlation

I want to try out to directly train on the ‘corr’ on which we are scored on. For this I would have to implement the Spearman correlation and get the gradient and hessian to be able to use it as a custom loss function in xgboost (or keras etc.). So far I was able to implement it in tensorflow and also get the gradient but the hessian does not work yet. I created a question with the details on stackoverflow:

Maybe someone of you has already tried to do something similar and knows why my code isn’t quite right yet.

A couple people have been trying this. Check out


I can’t find where I read it, but I believe the fast-soft-sort package’s Spearman function is only differentiable once, which would cause your None issue. You could try @mdo’s solution, which is to just use a matrix of ones as the Hessian.

Thanks for the reply. I got it working by setting the hessians to 1 instead of actually calculating them. I’m able to train with it in xgboost but even after quite some parameter tuning I’m so far not able to get better results than from just using rmse or similar standard loss functions.