【发布时间】:2016-10-31 23:59:10
【问题描述】:
现在我已经弄清楚如何使用 OLS (Pandas/Statsmodel OLS predicting future values),我正在尝试为我的数据拟合一条更好的曲线...GLM 应该可以像我假设的那样工作。
import statsmodels.api as sma
df1['intercept'] = 1
y = df1[['intercept', 'date_delta']]
X = df1['monthly_data']
smaresults_normal = sma.GLM(X,y, family=sma.families.Binomial()).fit()
返回 ValueError: The first guess on the deviance function returned a nan. This could be a boundary problem and should be reported.,这是 2010 年的一个已知问题。我也尝试过:
import statsmodels.api as sm
import statsmodels.formula.api as smf
glm_unsmoothed = smf.GLM('monthly_data ~ date_delta', df1, family=sm.families.Binomial() )
glm_unsmoothed.fit()
引发错误'builtin_function_or_method' object has no attribute 'equals'
我想用 ols 模型绘制模型以及未来值:
#ols model
df1['intercept'] = 1
X = df1[['intercept', 'date_delta']]
y = df1['monthly_data']
smresults_normal = sm.OLS(y, X).fit()
#future values
smresults_normal.predict(df_future12[['intercept', 'future_monthly']])
#model in sample data
import statsmodels.formula.api as smf
smresults_unsmoothed = smf.ols('monthly_data ~ date_delta', df1).fit()
df1['ols_preds_unsmoothed'] = smresults_unsmoothed.predict()
edit 我放弃了尝试使用 GLM,而是使用 OLS 和一个多项式拟合的公式,我认为它工作得很好......(尽管获得未来的预测显然与我的另一个OLS,有朝一日我希望能写一些代码而不用无休止的摆弄!)!不幸的是,我的声誉太低,无法发布漂亮的照片! :(
【问题讨论】:
-
具有家族二项式的 GLM,或 Logit 或 Probit 用于二进制数据。因变量或响应变量 endog 需要介于零和一之间,或者二进制,零和一。
-
感谢您的洞察力!我正在尝试使电源形式现在起作用(有一些困难)。我需要一些指数或抛物线(在 Excel 中,数据符合二次曲线 - 我正在运行另一个分析以进行比较)......我是否使用 GLM 朝着正确的方向前进?
-
我想问最后一个问题,当你想进行 log/exp 转换但数据不是二项式时,你应该使用什么?
标签: python statsmodels