Marine implot with equation and text R2

In my usual data analysis job, I switched to using 100% python since the saborn package is becoming available. Many thanks to this wonderful package. However, one excel-chart function that I skip is to display the polyphyte equation and / or the value of R2 when using the lmplot () function. Does anyone know an easy way to add this?

+6
source share
1 answer

This cannot be done automatically with lmplot , because it is undefined that should match this value in the presence of multiple regression approaches (i.e. using the hue , row or col variable).

But this is part of a similar jointplot function. By default, it shows the correlation coefficient and p value:

 import seaborn as sns import numpy as np x, y = np.random.randn(2, 40) sns.jointplot(x, y, kind="reg") 

But you can pass any function. If you want R ^ 2, you can do:

 from scipy import stats def r2(x, y): return stats.pearsonr(x, y)[0] ** 2 sns.jointplot(x, y, kind="reg", stat_func=r2) 

enter image description here

+13
source

Source: https://habr.com/ru/post/974576/


All Articles