def preds(k): 从datetime导入datetime y_temp = np.zeros((len(test_vec),3)) y_pred = np.zeros((len(test_vec),3)) i = 0; 从sklearn.model_selection导入KFold kf = KFold(n_splits = k,random_state = 2)
for train_index, test_index in kf.split(data):
print(data)
print(target)
print(train_index)
print(test_index)
K.clear_session()
start=datetime.now()
print('fold====================>>>>>>>>>>',i+1)
#X_train , X_test = data[train_index].values, data[test_index].values
#y_train , y_test = target[train_index].values, target[test_index].values
a=np.asarray(data[train_index])
b=np.asarray(data[test_index])
c=np.asarray(target[train_index])
d=np.asarray(target[test_index])
model = None
num_filters = [64, 128, 256, 512]
model=vdcnn_model()
early_stopping =EarlyStopping(monitor='val_loss', patience=5)
bst_model_path = 'cv10_best_weights'+str(i+1) + '.h5'
model_checkpoint = ModelCheckpoint(bst_model_path, save_best_only=True, save_weights_only=True)
hist = model.fit(a, c, \
validation_data=(b, d), \
epochs=200, batch_size=256,callbacks=[early_stopping, model_checkpoint])
bst_val_score = min(hist.history['val_loss'])
print('bst_val_score',bst_val_score)
#model.load_weights(bst_model_path)
#model.fit(data, y,epochs=2, batch_size=256, shuffle=True,)
#y_temp = model.predict([test_data], batch_size=256, verbose=1)
#y_pred+=y_temp
end=datetime.now()
print(" ")
print('time taken for this fold', end-start)
i+=1
preds(2)
giving-
IndexError Traceback (most recent call last)
<ipython-input-105-6de2161fc4d0> in <module>()
----> 1 preds(2)
<ipython-input-104-bf8abb1717a0> in preds(k)
17 #X_train , X_test = data[train_index].values, data[test_index].values
18 #y_train , y_test = target[train_index].values, target[test_index].values
---> 19 a=np.asarray(data[train_index])
20 b=np.asarray(data[test_index])
21 c=np.asarray(target[train_index])
IndexError: indices are out-of-bounds
我尝试了所有方法-.values,.asarray,.array,as_matrix(),但仍然遇到相同的错误。