seaborn回归图---回归模型图Implot、线性回归图regplot、线性回归残差图residplot
分类:
Seaborn
回归图只要探讨两连续数值变量的变化趋势情况,绘制x-y的散点图和回归曲线。
1.lmplot
1 | 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"
。
举例:
1 | sns.lmplot(x = "sepal_length" , y = "sepal_width" , hue = "species" , data = iris) |
2.regplot
1 | 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
会自动完成线性回归拟合。
举例:
1 | sns.regplot(x = "sepal_length" , y = "sepal_width" , data = iris) |
3.residplot
1 | 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 ) |
功能:展示线性回归模型拟合后各点对应的残值
举例:可以对以年为单位的地震记录作线性回归拟合。以下两张图分别对应一阶线性回归拟合、拟合后残值分布情况图。
1 2 3 4 5 6 7 8 9 10 11 12 13 | 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() |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 使用C#创建一个MCP客户端
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 按钮权限的设计及实现