Feature request: allow constraints on cubic spline e.g. strictly increasing
Opened this issue · 3 comments
My fitted splines produce a result with decreasing regions, is this expected? If so, please may we implement a constraint setting which enforces that the splines be strictly increasing (other options like nondecreasing could be helpful for others too).
Cobs in R can do this sort of thing when fitting splines: https://stats.stackexchange.com/questions/179283/strictly-increasing-interpolation-spline
Thanks for the question. Yes, it is possible to have the calibration curve be decreasing over some intervals. Sometimes this is appropriate. Assuming you have regularized appropriately, what it means is that (on the calibration set) the data suggest the probability of "success" is actually lower for x_2 than it is for x_1 even though x_2 > x_1. This happens not infrequently with under-fit models. For example, you are modeling the probability of having a particular disease vs age, and the truth is that risk goes up with age until age 65, but then goes down. If you fit a simple logistic regression, it will have the probability continuing to rise with age (due to the simplicity of the model space). Then when you apply calibration, it will attempt ro "correct" this, by having a non-monotonic calibration curve.
I looked into trying to add a non-monotonic option, but didn't know of a way to enforce that constraint. The splines I use are very specific in that they:
- Use log-likelihood rather than least-squares as the fit criterion
- Are penalized with the integrated second derivative ("smoothing spline")
- Are fit to the transformed probabilities (i.e. on the log-odds scale).
I think this makes some of the standard methods of enforcing monotonicity ineffective. I did look at this once and did not find an easy solution. If you know of a good reference that describes how to do this, I'd be happy to take a look. It would be a nice feature.
Thank you very much for addressing this. Totally agree about it sometimes being appropriate. Unfortunately, in my use case, I need to enforce that the calibrator does not change the rank of the results (=> enforce that the calibration function is strictly increasing). I don't know a reference other than having a look at how Cobs
in R
does this. However, please may we retain this issue a feature request?
We can absolutely keep this as a feature request.
One other idea as a workaround. If you set unity_prior=True
and increase unity_prior_weight
, at some point it will force the calibration curve(s) to be monotonic. So, you might be able to achieve what you want by gradually increasing the unity_prior_weight
until monotonicity is achieved...