How to remove TypeError: 'module' object is not callable in GLM

How to remove TypeError: 'module' object is not callable in GLM

我正在尝试在 python 3.1 中拟合 GLM 模型。我正在使用 Gaussian link 函数。所以我写了

import statsmodels.api as sm 
glm=sm(y_train, X_train, family=sm.families.Gaussian())

但我收到错误消息

TypeError: 'module' object is not callable

你能建议我如何处理这个错误吗?

你叫 sm,这是一个 'module' 对象,而你应该叫 sm.GLM。您的代码应该是:

import statsmodels.api as sm 
glm=sm.GLM(y_train, X_train, family=sm.families.Gaussian())

在此处查看 GLM 的官方参考资料:https://www.statsmodels.org/stable/glm.html