GLM-in-statsmodel返回

2024-10-01 11:29:34 发布

您现在位置:Python中文网/ 问答频道 /正文

现在我已经知道了如何使用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年的一个已知问题。我也试过:

^{pr2}$

这会引发错误'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()

编辑我放弃了使用GLM的尝试,而是使用了一个多项式拟合公式的OLS,我认为这个公式非常有效……(虽然得到未来的预测显然与我其他OLS中的不一样,但总有一天我会希望自己能写一些代码而不需要无休止的修改!)!不幸的是,我的名声太低了,不能发布这张漂亮的照片!:(


Tags: datadatefuturefitdeltadf1normalsma
1条回答
网友
1楼 · 发布于 2024-10-01 11:29:34

我想我也有同样的问题,你只需要确保你的数据帧不包含大小写都等于零的行。在估算glm之前,运行:

data=数据[(数据.案例!=0)|(数据.notcases!=0)]

显然R是自动完成的。在

相关问题 更多 >