Python Forum

Full Version: Seaborn regplot regression equation?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello all,

I hope it is OK to ask a seaborn question in this section. Please direct me elsewhere if not.

In a Jupyter Notebook, I generate a seaborn regplot with a robustregression line and no confidence intervals (image link below if required):

sns.regplot(x=ohm["ia"], y=ohm["urv"],robust=True, ci=None, line_kws={"color":"r","alpha":0.7,"lw":2}) 
plt.grid(True)
plt.xlim(0,0.05)
plt.ylim(0, 6)
plt.xlabel('$I(A)$') #
plt.ylabel('$Ur(V)$')
plt.title('Caractéristiques du dipôle $U=f(I)$')
I would like to display the regression equation in the legend, but I cannot find a way to display the regression equation. I know how to derive it in code, but it occurs to me that regplot must have a method to recover the coefficients directly since by definition it plots the regression line. Is there a way to get to it?

I don't think I can attach a csv file here. It's a short and simple dataset though:

ia,urv
0,0
0.0092,1.1
0.0105,1.9
0.0244,3
0.034,4.2
0.041,4.9
0.049,6

Thank you for your suggestions.

All the best.c
Regplot image here
Went searching, on another site:
Quote:In 2015, the lead developer for seaborn replied to a feature request asking for access to the statistical values used to generate plots by saying, "It is not available, and it will not be made available."

So, unfortunately, this feature does not exist in seaborn, and seems unlikely to exist in the future.

Update: in March 2018, seaborn's lead developer reiterated his opposition to this feature. He seems... uninterested in further discussion.

SciKitLearn on the other hand will calculate your regression and give you the coefficients. You then use matplotlib to draw your graph and add the text, so 2 steps instead of one. That would be my recommendation...
J
(Jun-09-2020, 12:51 PM)jefsummers Wrote: [ -> ]Went searching, on another site:
Quote:In 2015, the lead developer for seaborn replied to a feature request asking for access to the statistical values used to generate plots by saying, "It is not available, and it will not be made available."

So, unfortunately, this feature does not exist in seaborn, and seems unlikely to exist in the future.

Update: in March 2018, seaborn's lead developer reiterated his opposition to this feature. He seems... uninterested in further discussion.

SciKitLearn on the other hand will calculate your regression and give you the coefficients. You then use matplotlib to draw your graph and add the text, so 2 steps instead of one. That would be my recommendation...
J
Thank you very much jefsummers. That is bizarre, but seaborn does have features for which it is difficult to find an explanation. I am still searching an explanation of how the regression is implemented depending on whether "robust" is set as true or not. I haven't found anything enlightening yet. Calculating the coefficients is not hard but it would be easier to have those coefficients at hand when you do dozens of those plots with different regressions and data sets. Oh well, never mind and thank you for the explanation.