大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。
Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺
def LSTM_Classifier(train, trainLabel, test, testLabel, val_test, val_label, new_test=None):
train, test = np.array(train), np.array(test)
train, test = train.reshape(train.shape[0], 1, train.shape[1]), test.reshape(test.shape[0], 1, test.shape[1])
val_test = np.array(val_test)
val_test = val_test.reshape(val_test.shape[0], 1, val_test.shape[1])
new_test = np.array(new_test)
new_test = new_test.reshape(new_test.shape[0], 1, new_test.shape[1])
trainLabel = np_utils.to_categorical(trainLabel)
val_label = np_utils.to_categorical(val_label)
# 单向LSTM
model = Sequential()
model.add(LSTM(360, activation='relu', input_shape=(train.shape[1], train.shape[2])))
model.add(Dense(1024,activation='relu'))
model.add(LeakyReLU(alpha=0.001))
model.add(Dropout(0.4))
model.add(Dense(2, activation='sigmoid'))
# 双向LSTM
# model = Sequential()
# model.add(Bidirectional(LSTM(160,activation='relu', return_sequences=True), input_shape=(train.shape[1], train.shape[2])))
# model.add(Bidirectional(LSTM(160, activation='relu')))
#
# model.add(Dense(2, activation='sigmoid'))
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
model.fit(train, trainLabel, batch_size=10, epochs=10, verbose=0, validation_data=(val_test, val_label), shuffle=True)
pred_1 = model.predict_classes(test)
pred_2 = model.predict_classes(new_test)
return pred_1, pred_2
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/195097.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...