我希望从一个适合与pygam匹配的模型中提取合适的参数。这里是一个可重复的例子。
from pygam import LinearGAM, s, f
from pygam.datasets import wage
X, y = wage()
gam = LinearGAM(s(0) + s(1) + f(2)).fit(X, y)
以下是我尝试过的几件事。
#gam.summary() ## This does not show it.
#gam.intercept_ ## This does not exit.
#gam.terms.info ## This does not contain it.
#gam.partial_dependence(-1) ## This raises an error.
下面是一个尚未实现的相关GitHub问题:https://github.com/dswah/pyGAM/issues/85
发布于 2019-02-27 00:18:45
TL;DR
gam.coef_[-1]
提取。terms
属性来验证此行为。pygam.intercept
并将其包含到您的公式(例如gam = LinearGAM(intercept + s(0) + s(1) + f(2)).fit(X, y)
)中,您可以更加显式化。默认行为和条款
默认存储截距作为系数的最后一个,并且可以通过gam.coef_[-1]
提取。打印terms
属性以验证这一点。
from pygam import LinearGAM, s, f
from pygam.datasets import wage
X, y = wage()
gam = LinearGAM(s(0) + s(1) + f(2)).fit(X, y)
print(gam.terms)
# s(0) + s(1) + f(2) + intercept
print(gam.coef_[-1])
# 96.31496573750117
显式声明拦截
将截距显式地包含在公式中是一个好主意,这样您就不会依赖于截距是系数的最后一个元素。
from pygam import intercept
gam = LinearGAM(intercept + s(0) + s(1) + f(2)).fit(X, y)
print(gam.terms)
# intercept + s(0) + s(1) + f(2)
print(gam.coef_[0])
# 96.31499924945388
https://stackoverflow.com/questions/54895945
复制相似问题