TypeError:int()参数必须是字符串,类似字节的对象或数字,而不是“过滤器”

时间:2019-03-27 04:33:08

标签: python-3.x jupyter-notebook

我在执行此代码时遇到此错误。它适用于Logistic回归,但不适用于随机森林分类器。

我尝试了类似的问题,但没有找到解决方案

这是我的代码:

all_data=train.append(test)

train_ohd = all_data[all_data['Response']>0].copy()

test_ohd = all_data[all_data['Response']<1].copy()


l = train_ohd.shape[0]
ind_list = [(range(0,l//10), filter(lambda x: x not in range(0,l//10), range(0,l))), 
            (range(l//10,l//10*2), filter(lambda x: x not in range(l//10,l//10*2), range(0,l))),
            (range(l//10*2,l//10*3), filter(lambda x: x not in range(l//10*2,l//10*3), range(0,l))),
            (range(l//10*3,l//10*4), filter(lambda x: x not in range(l//10*3,l//10*4), range(0,l))),
            (range(l//10*4,l//10*5), filter(lambda x: x not in range(l//10*4,l//10*5), range(0,l))),
            (range(l//10*5,l//10*6), filter(lambda x: x not in range(l//10*5,l//10*6), range(0,l))),
            (range(l//10*6,l//10*7), filter(lambda x: x not in range(l//10*6,l//10*7), range(0,l))),
            (range(l//10*7,l//10*8), filter(lambda x: x not in range(l//10*7,l//10*8), range(0,l))),
            (range(l//10*8,l//10*9), filter(lambda x: x not in range(l//10*8,l//10*9), range(0,l))),
            (range(l//10*9,l), filter(lambda x: x not in range(l//10*9,l), range(0,l)))]

ld = [labels_decoder1,labels_decoder2,labels_decoder3,labels_decoder4,labels_decoder5,labels_decoder6,labels_decoder7,
      labels_decoder8,labels_decoder9,labels_decoder10,labels_decoder11,labels_decoder12,labels_decoder13]

i = 0
for l in ld:
    i = i + 1    

    for j in range(10):

        X_1, X_2 = ind_list[j][1], ind_list[j][0]
        y_1, y_2 = train_ohd.iloc[X_1]['Response'], train_ohd.iloc[X_2]['Response']

        rf = RandomForestClassifier(n_estimators=500, random_state=1)
        rf.fit(train_ohd[features].iloc[X_1],l(y_1))
        train_ohd['rf%s' % (i)].iloc[X_2] = rf.predict_proba(train_ohd[features].iloc[X_2]).T[1]

0 个答案:

没有答案