zoukankan      html  css  js  c++  java
  • seaborn回归图---回归模型图Implot、线性回归图regplot、线性回归残差图residplot

    回归图只要探讨两连续数值变量的变化趋势情况,绘制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)
    • seaborn.lmplot
    • 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)

    功能:用线性回归模型对数据做拟合

    • seaborn.regplot
    • 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()
  • 相关阅读:
    Linux 终端常用快捷键
    问题集
    数据库
    mysql数据库知识点
    IntelliJ IDEAj集成开发环境
    Windows最全DOS的CMD命令
    DB2移植到Oracle数据库完整的图解教程
    169.254是什么IP地址 169.254的解决方法(添加局域网地址时)
    解析xml时报错
    童年乐趣
  • 原文地址:https://www.cnblogs.com/nxf-rabbit75/p/12098549.html
Copyright © 2011-2022 走看看