PerfectSeparationError:检测到完美分离,结果不可用

问题描述

我正在尝试使用 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,1,-1
  elif choices[trial_i] == 1 and rewards[trial_i] == 1: #right reward
    c,r=1,1
  elif choices[trial_i] == 1 and rewards[trial_i] == 0: #right & no reward
    c,-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 

非常感谢!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)