Python statsmodels中的GLM伽玛回归 [英] GLM gamma regression in Python statsmodels

查看:75
本文介绍了Python statsmodels中的GLM伽玛回归的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑在Python包statsmodel中拟合GLM伽玛函数.

Consider the GLM gamma function fitting in Python package statsmodel.

这是代码:

import numpy
import statsmodels.api as sm

model = sm.GLM(ytrain, xtrain, family=sm.families.Gamma(link = sm.genmod.families.links.identity)).fit()

print model.summary()

这为我提供了通过伽马回归获得的拟合模型参数的摘要.我感兴趣的是上述模型的确切pdf $ P(y | X)$.到目前为止,我可以收集的是model.params * x给出了伽玛平均值作为训练数据的函数.如何从摘要中推断pdf的形状?

This gives me the summary of the fitted model parameters, obtained by a gamma regression. What I am interested in, is the exact pdf $P(y | X)$ from the above model. What I can gather so far is the model.params*x gives the mean of the gamma as a function of the training data. How to infer the shape of the pdf from the summary ?

推荐答案

GLM 具有 get_distribution 方法,该方法返回具有转换后的参数化的scipy.stats分发实例.分发实例将具有所有可用的方法,例如pdf,cdf和rvs.

GLM has a get_distribution method that returns a scipy.stats distribution instance with the transformed parameterization. The distribution instance will have all the available methods like pdf, cdf and rvs.

http://www.statsmodels.org/devel/generation/statsmodels.genmod.generalized_linear_model.GLM.get_distribution.html

目前仅在某些特定情况下在内部使用.

This is currently used only internally for some limited cases.

请注意,同一性链接不能保证所有解释变量集的均值均为正.

Note, the identity link does not guarantee that the mean is positive for all sets of explanatory variables.

这篇关于Python statsmodels中的GLM伽玛回归的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆