【发布时间】:2016-08-25 00:15:02
【问题描述】:
尝试实现稳健的统计数据而不是普通最小二乘 (OLS) 拟合,这样离群值对我来说就不是问题了。 我希望在 seaborn 的 pairplot 函数中实现这一点,但从 AP 文档中看不到和添加它的简单方法,因为似乎没有适合的关键字参数。
来自:scipy lectures 他们建议使用以下内容,但我猜那是用于 regplot 的地方,您可以使用
`fit = statsmodels.formula.api.rlm()`
这里是一些示例代码
import seaborn as sns; sns.set(style="ticks", color_codes=True)
import matplotlib.pyplot as plt
%matplotlib inline
iris = sns.load_dataset("iris")
sns.pairplot(iris, kind="reg")#, robust = True)
plt.show()
提前致谢!
编辑:我找到了一种解决方法,但显然松开了可以在 pairplot 上完成的“色调”功能。为pairplot添加强大的选项将是一个不错的功能。 代码:
def corrfunc(x, y, **kws):
r, _ = stats.pearsonr(x, y)
ax = plt.gca()
ax.annotate("r = {:.2f}".format(r), xy=(.1, .9), xycoords=ax.transAxes)
g = sns.PairGrid(df1, palette=["red"])
g.map_upper(sns.regplot, robust = True)
g.map_diag(sns.distplot, kde=True)
g.map_lower(sns.kdeplot, cmap="Blues_d")
g.map_lower(corrfunc)
【问题讨论】:
-
我找到了一种解决方法,但显然松开了可以在 pairplot 上完成的“色调”功能。为pairplot添加强大的选项将是一个不错的功能。代码:` def corrfunc(x, y, **kws): r, _ = stats.pearsonr(x, y) ax = plt.gca() ax.annotate("r = {:.2f}".format( r), xy=(.1, .9), xycoords=ax.transAxes) g = sns.PairGrid(df1, palette=["red"]) g.map_upper(sns.regplot, robust = True) g.map_diag (sns.distplot, kde=True) g.map_lower(sns.kdeplot, cmap="Blues_d") g.map_lower(corrfunc) `
-
在您的解决方法中,您可以使用 g = sns.PairGrid(df1, hue='species') 包含色调
标签: statistics linear-regression seaborn