'NoneType'对象不可下标错误

时间:2019-12-19 09:35:04

标签: python keras deep-learning

我在获取培训和测试数据时遇到了麻烦。我将数据分为七种类型。然后,我们创建了一个再次组合数据的函数。但是,当我运行它时,训练数据为“无”,并且出现以下错误消息:

'NoneType' object is not subscriptable

请告诉我该怎么做(变量数据的形状为(len(data),2))

    def get_train_And_test(self, data, percent = 80):
        if percent > 100 :
            print('파라미터를 확인해주세요')
            return 
        target1=[]
        trainx=[]
        testx=[]
        criteria1=0
        for i in range(7):
          target1.append([])    
        for i in range(len(data)):
            if data[i, 0] < 0.5 and data[i, 1] < 0.5 :
                target1[0].append(data[i])
            elif data[i, 0] >= 0.5 and data[i, 1] < 0.5 :
                target1[1].append(data[i])
            elif data[i, 0] < 0.5 and data[i, 1] >= 0.5 :
                target1[2].append(data[i])
            elif data[i, 0] >= 0.5 and data[i, 0] < 0.75 and data[i,1]>=0.5 and data[i,1]<0.75:
                target1[3].append(data[i])
            elif data[i, 0] >= 0.5 and data[i, 0] < 0.75 and data[i,1] >= 0.75:
                target1[4].append(data[i])
            elif data[i, 1] >= 0.5 and data[i, 0] >= 0.75 and data[i,1] < 0.75:
                target1[5].append(data[i])
            elif data[i, 0] >= 0.75 and data[i, 1] >= 0.75:
                target1[6].append(data[i])
        for i in range(7):
          criteria = int(len(target1[i]) * percent / 100)
          trainx.extend(target1[i][0 : criteria])
          testx.extend(target1[i][criteria: ])
          criteria1+=criteria
        np.random.shuffle(trainx);np.random.shuffle(testx);
        print('기준 ', criteria1)
        return (trainx,testx)

    (x_train, x_test) = analysis.get_train_And_test(data, 80)
    print(x_train[0:4])

结果:


TypeError                                 Traceback (most recent call last)
<ipython-input-77-cbab7c630a54> in <module>()
      1 (x_train, x_test) = analysis.get_train_And_test(data, 80)
----> 2 print(x_train[0:4])
      3 (t_train, t_test) = analysis.get_train_And_test(encoded_target, 80)
      4 print(t_train[0:4])
      5 (x_train2, x_test2) = analysi2.get_train_And_test(data2, 80)

TypeError: 'NoneType' object is not subscriptable

0 个答案:

没有答案