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

2024-05-18 20:14:52 发布

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

我试图使用sm.GLM二项式拟合函数,但它一直给我提供完美的分离误差。我对这个函数很陌生,所以请帮帮我! 可选择带形状的阵列(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 

非常感谢你


Tags: andnonenpzerosregchoicessmglm

热门问题