开始使用免费开始使用

绘制数据与线性模型拟合

在之前的练习中,您已经练习了如何拟合并解读 Poisson 回归模型。在本练习中,您将先对 crab 数据进行可视化分析,然后再查看模型拟合结果。

首先,您将对数据绘制一个线性拟合曲线,稍后将用它与 Poisson 回归的拟合值进行比较。

本练习是课程的一部分

Python 中的广义线性模型

查看课程

练习说明

  • 导入 seabornmatplotlib 库。
  • 使用 crab 数据集绘制散点图,x 轴为 width,y 轴为 sat,并对 sat 变量添加 0.3 的抖动。
  • 通过将参数 fit_reg 设为 True 来添加线性模型拟合。
  • 将拟合线的 'color' 设置为 'green',并将 'label' 设置为 'LM fit'

交互式实操练习

通过完成这段示例代码来试试这个练习。

# Import libraries
import ____ as sns
import ____.pyplot as plt

# Plot the data points and linear model fit
sns.regplot(____, ____, data = ____,
            y_jitter = ____,
            fit_reg = ____,
            line_kws = {'color':____, 
                        'label':____})

# Print plot
plt.show()
编辑并运行代码