python - How to run a GLM gamma regression in Python with R like formulas
问题描述
I am running a GLM regression in Python using statsmodels using the following code. I specifically want to implement a log link function. I am able to write R like formulas using Statsmodels.
The following code successfully runs but throws up a Deprecation Warning. Can anyone suggest how to get rid of this warning. Thanks for the help.
Code:
mod = smf.glm(formula='y ~ C(x1) + C(x2) + C(x3) + x4 + x5', data=data,family=sm.families.Gamma(link=sm.families.links.log))
reg = mod.fit()
print(reg.summary())
Warning: DeprecationWarning: Calling Family(..) with a link class as argument is deprecated. Use an instance of a link class instead.
解决方案
我认为以上任何一个答案都不正确。按照警告的指示,正确的方法是使用括号内的链接函数的相应实例:
mod = smf.glm(formula='y ~ C(x1) + C(x2) + C(x3) + x4 + x5', data=data,family=sm.families.Gamma(link=sm.families.links.log()))
reg = mod.fit()
print(reg.summary())
推荐阅读
- python - 根据另一个列表的内容从一个列表中删除项目
- matlab - 链接 matlab 的库时出现“没有制定目标的规则”错误
- php - 使用laravel一键更改两条记录的状态
- angular - 如何将我在 Angular 中的前端与我的 Spring Boot 应用程序集成?
- python - 在 mayavi 中绘制断开的线,调用 mlab.plot3d 一次
- vue.js - Dropzone 图片上传动态 URL
- c# - PactNet - 如何在同一个测试运行中运行多个 Pact json?
- python - 如何将我的数组拆分为具有 10 个元素的小数组并每次移动 2 个元素?
- elasticsearch - 用于搜索术语并在日期范围内的弹性查询
- postgresql - 尝试在 PostgreSQL 10 中选择数据时出现查询错误