卡方分箱问题

while (len(groupIntervals) > split_intervals): # 终止条件: 当前分箱数=预设的分箱数 # 每次循环时, 计算合并相邻组别后的卡方值。具有最小卡方值的合并方案,是最优方案 chisqList = [] for k in range(len(groupIntervals) - 1): # 两两合并的次数 temp_group = groupIntervals[k] + groupIntervals[k + 1] df2b = regroup.loc[regroup['temp'].isin(temp_group)] # 找出区间的样本 chisq = Chi2(df2b, 'total', 'bad', overallRate) chisqList.append(chisq) # groupIntervals -1 个卡方值 best_comnbined = chisqList.index(min(chisqList)) # 找到卡方值最小的位置 groupIntervals[best_comnbined] = groupIntervals[ best_comnbined] + groupIntervals[best_comnbined + 1] # after combining two intervals, we need to remove one of them # groupIntervals.remove(groupIntervals[best_comnbined]) groupIntervals.remove(groupIntervals[best_comnbined ]) 这段代码的第14行,是不是应该修改为`groupIntervals.remove(groupIntervals[best_comnbined+1 ])`

要回复问题请先登录注册