Open Gabriel-Kissin opened 1 month ago
An easy fix would be to scale the data before fitting the regression.
I'm inclined to agree with the statsmodels folks that there is no one obviously best algorithm to use here, and also that scaling the data should be a very easy workaround to avoid this if you run into it.
With large values, the regression line can be done incorrectly:
The first three lines are good, the last three aren't. (Note also the strange shape of the green shaded region which is the same issue).
This is not strictly a seaborn issue - see https://github.com/statsmodels/statsmodels/issues/9258 where there is some further information about this. However, as other OLS methods implemented by statsmodels (QR) produce an accurate fit in these cases, as does sklearn (dotted black line), I thought it might be worth posting here. Perhaps worth considering whether a more robust algorithm which doesn't lead to these issues can be used to simplify the line of best fit visualisation process.
The code used to generate the above plot is