我想使用python3构建一个零膨胀泊松模型,我在statsmodel
库中发现了statsmodels.discrete.count_model.ZeroInflatePoisson
函数。
但是我不确定如何使用它。看起来我应该这样做:
ZIFP(Y_train,X_train).fit()
。
但是当我想使用X_test
进行预测时,它告诉我X_test
的长度与X_train
不匹配。
或者是否有其他包适用于拟合这个模型?
这是我使用的代码:
X1 = [random.randint(0,1) for i in range(200)]
X2 = [random.randint(1,2) for i in range(200)]
y = np.random.poisson(lam = 2,size = 100).tolist()
for i in range(100):y.append(0)
df['x1'] = x1
df['x2'] = x2
df['y'] = y
df_x = df.iloc[:,:-1]
x_train,x_test,y_train,y_test = train_test_split(df_x,df['y'],test_size = 0.3)
clf = ZeroInflatedPoisson(endog = y_train,exog = x_train).fit()
clf.predict(x_test)
ValueError:operands could not be broadcat together with shapes (140,)(60,)
也尝试过:
clf.predict(x_test,exog = np.ones(len(x_test)))
ValueError: shapes(60,) and (1,) not aligned: 60 (dim 0) != 1 (dim 0)
ZeroInflatedPoisson
,fit
和predict
的使用方式与statsmodels中的其他模型相同,只是增加了用于零膨胀部分的选项。 - undefined