回归图只要探讨两连续数值变量的变化趋势情况, 绘制 x-y 的散点图和回归曲线.
- 1.lmplot
- seaborn.lmplot(x, y, data, hue=None, col=None, row=None, palette=None, col_wrap=None, height=5, aspect=1, markers='o', sharex=True, sharey=True, hue_order=None, col_order=None, row_order=None, legend=True, legend_out=True, x_estimator=None, x_bins=None, x_ci='ci', scatter=True, fit_reg=True, ci=95, n_boot=1000, units=None, order=1, logistic=False, lowess=False, robust=False, logx=False, x_partial=None, y_partial=None, truncate=False, x_jitter=None, y_jitter=None, scatter_kws=None, line_kws=None, size=None)
lmplot 同样是用于绘制回归图, 但 lmplot 支持引入第三维度进行对比, 例如我们设置 hue="species".
举例:
- sns.lmplot(x="sepal_length", y="sepal_width", hue="species", data=iris)
- 2.regplot
- seaborn.regplot(x, y, data=None, x_estimator=None, x_bins=None, x_ci='ci', scatter=True, fit_reg=True, ci=95, n_boot=1000, units=None, order=1, logistic=False, lowess=False, robust=False, logx=False, x_partial=None, y_partial=None, truncate=False, dropna=True, x_jitter=None, y_jitter=None, label=None, color=None, marker='o', scatter_kws=None, line_kws=None, ax=None)
功能: 用线性回归模型对数据做拟合
regplot 绘制回归图时, 只需要指定自变量和因变量即可, regplot 会自动完成线性回归拟合.
举例:
- sns.regplot(x="sepal_length", y="sepal_width", data=iris)
- 3.residplot
- seaborn.residplot(x, y, data=None, lowess=False, x_partial=None, y_partial=None, order=1, robust=False, dropna=True, label=None, color=None, scatter_kws=None, line_kws=None, ax=None)
功能: 展示线性回归模型拟合后各点对应的残值
举例: 可以对以年为单位的地震记录作线性回归拟合. 以下两张图分别对应一阶线性回归拟合, 拟合后残值分布情况图.
- plt.figure(figsize=(12,6))
- plt.subplot(121)
- sns.regplot(x="Year", y="ID",
- data=temp,order=1) # default by 1plt.ylabel(' ')
- plt.title('Regression fit of earthquake records by year,order = 1')
- plt.subplot(122)
- sns.residplot(x="Year", y="ID",
- data=temp)
- plt.ylabel(' ')
- plt.title('Residual plot when using a simplt regression
- model,order=1')
- plt.show()
来源: http://www.bubuko.com/infodetail-3349798.html