Python Forum
Seaborn regplot regression equation?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Seaborn regplot regression equation?
#1
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
Reply
#2
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
Reply
#3
(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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Seaborn not displaying the specified n bins russellm10 0 541 Jun-28-2023, 02:51 AM
Last Post: russellm10
  Seaborn and Pandas russellm10 0 1,273 Nov-20-2021, 04:01 PM
Last Post: russellm10
  Reset seaborn ju21878436312 2 4,995 Jun-15-2021, 09:31 AM
Last Post: ju21878436312
  Seaborn clustermap clustered data YoYo1975 2 2,266 Feb-05-2020, 09:08 AM
Last Post: YoYo1975
  Error when installing Seaborn package using pip chawkins 3 5,541 Jul-16-2018, 12:12 AM
Last Post: Larz60+
  Why can't I import seaborn module? Athenaeum 1 6,436 Dec-09-2017, 08:40 AM
Last Post: buran
  Overlay two lines on a single seaborn plot pemfir 1 22,793 Oct-28-2016, 10:51 PM
Last Post: Ofnuts

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020