英文:
Fitting GammaRegressor() and getting the scale and shape parameters
问题
我的反应变量遵循伽玛分布,我尝试使用scikit-learn中的GammaRegressor:
model = GammaRegressor()
model.fit(X_train_scaled, y_train)
pred_gamma = model.predict(X_test_scaled)
在这种情况下,形状和尺度参数是什么,以及GammaRegressor如何计算它们?
这是我的原始数据的形状和尺度:
from scipy.stats import gamma
shape_k, loc, scale = gamma.fit(y_train)
print(shape_k, loc, scale)
英文:
My response variable follows a gamma distribution and I'm trying to use gammaRegressor from scikit-learn:
model = GammaRegressor()
model.fit(X_train_scaled, y_train)
pred_gamma = model.predict(X_test_scaled)
What are the shape and the scale parameters in this case and how does GammaRegressor calculate them?
This the shape and scale of my original data:
from scipy.stats import gamma
shape_k, loc, scale = gamma.fit(y_train)
print(shape_k, loc, scale)
答案1
得分: 1
GammaRegressor
拟合一个模型,使目标变量在独立变量的线性函数(经过链接函数处理)条件下服从伽马分布,而你的最后一段代码估计目标变量自身服从伽马分布。回归的预测结果是对应伽马分布的均值,分布的形状参数被假定为恒定的(可以估计,但据我了解,sklearn没有暴露这个参数)。
有关更多细节,这里不是合适的讨论地点,但可以参考例如以下链接:
这些
三个
问题
涉及到R的实现,以及statsmodels
中的广义线性模型文档。
英文:
GammaRegressor
fits a model such that the target variable is gamma-distributed conditional on a (link function applied to a) linear function of the independent variables, whereas your last code estimates the target variable as gamma-distributed by itself. The predictions out of the regression are the mean of the corresponding gamma distribution, and the shape parameter of the distribution is assumed to be constant (and can be estimated, but as far as I can tell isn't exposed by sklearn).
For more details it becomes off-topic here, but see e.g.
these
three
questions
on stats.SE involving R's implementation, and the statsmodels
documentation for GLMs.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论