KeyError:“ [Int64Index([... dtype ='int64',length = 802)]都不存在

时间:2020-08-05 13:29:04

标签: python pandas keras neural-network

使用keras时如何处理该索引问题?看着我的形状,一切看起来都很正常:

X = DF.iloc[:, 0:10]
Y = DF.iloc[:, 10:15]

X.shape, Y.shape

((1003, 10), (1003, 5))

X e Y:

enter image description here

enter image description here

培训:

for train, test in kfold.split(X,Y):

    model = Sequential()
    model.add(Dense(10,
                kernel_regularizer=l2(0.001),
                kernel_initializer=VarianceScaling(), 
                activation='sigmoid',
                name='hidden-input'))
    model.add(Dense(5, 
                kernel_regularizer=l2(0.001),
                kernel_initializer=VarianceScaling(),                 
                activation='sigmoid',
                name='output'))
    
    model.compile(loss='mse', optimizer='adam', metrics=['mse'])
    
    model.fit(X[train], Y[train], epochs=50, batch_size=5, verbose = 0,
              validation_data=(X[test], Y[test]))

    scores = model.evaluate(X[test], Y[test], verbose=0)
    print("%s: %.2f%%" % (model.metrics_names[1], scores[1]*100))
    cvscores.append(scores[1] * 100)

输出:

KeyError: "None of [Int64Index([ 201,  202,  203,  204,  205,  206,  207,  208,  209,  210,\n            ...\n             993,  994,  995,  996,  997,  998,  999, 1000, 1001, 1002],\n           dtype='int64', length=802)] are in the [columns]"

0 个答案:

没有答案