我正在尝试使用 sm.GLM 二项式拟合函数,但它不断给我完美的分离错误。我对这个功能真的很陌生,所以请帮助我!选择是带有形状的ndarray(15978,)。
nChoices = len(choices)
nBack = 100
reg_c = np.zeros(nBack)
reg_r = np.zeros(nBack)
reg_x = np.zeros(nBack)
predictors = np.zeros((nChoices, 3*nBack))
for trial_i in range(nChoices):
predictors[trial_i] = np.concatenate((reg_c, reg_x, reg_r), axis=None)
if choices[trial_i] == 0 and rewards[trial_i] == 1: #left reward
c,x,r=-1,-1,1
elif choices[trial_i] == 0 and rewards[trial_i] == 0: #left & no reward
c,x,r=-1,1,-1
elif choices[trial_i] == 1 and rewards[trial_i] == 1: #right reward
c,x,r=1,1,1
elif choices[trial_i] == 1 and rewards[trial_i] == 0: #right & no reward
c,x,r=1,-1,-1
else:
print("oh no things are bad")
reg_c = np.concatenate((c,reg_c[:-1]),axis=None)
reg_r = np.concatenate((r,reg_r[:-1]),axis=None)
reg_x = np.concatenate((x,reg_x[:-1]),axis=None)
glm_binom = sm.GLM(choices,sm.add_constant(regressors),family=sm.families.Binomial())
#running the model
glm_result = glm_binom.fit() #this is the problem area
weights_py = glm_result.params
太感谢了!