SVM可以完美运行,但LSTM会显示错误,并且任何人也可以协助将代码添加到GRU中
def RandomEnviromentForActive(x_train, x_test,y_train):
# Randomize a classifier
Index = np.random.randint(1, 3)
#print(Index)
global IndexName
# Choose to use the SVC classifier
if Index == 1:
IndexName = 'Classifiers are:SVC'
svc_model = svm.SVC(kernel='rbf', C= 1)
svc_model.fit(x_train, y_train)
pred_svc = svc_model.predict(x_test)
pred = pred_svc[0]
#elif Index == 2:
model = Sequential()
#model.add(Embedding(max_features, output_dim=256))
model.add(LSTM(128))
#model.add(Dropout(0.5))
model.add(Dense(1, activation='sigmoid'))
model.compile(loss='binary_crossentropy',
optimizer='rmsprop',
metrics=['accuracy'])
model.fit(x_train, y_train)
pred_LSTM = model.predict(x_test)
pred = pred_lstm[0]
return pred