test_model_fjs.py 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  1. import sys
  2. from keras.models import Model
  3. from keras.layers import Input, LSTM, Dense
  4. import numpy as np
  5. import pandas as pd
  6. from matplotlib import pyplot
  7. from BiddingKG.dl.common.models import *
  8. from sklearn.metrics import classification_report
  9. sys.path.append(os.path.abspath("../.."))
  10. model_file = "model_person_classify_fjs.model.hdf5"
  11. def getSeq2seqModel():
  12. # Batch size for training.
  13. batch_size = 64
  14. # Number of epochs to train for.
  15. epochs = 100
  16. # Latent dimensionality of the encoding space.
  17. latent_dim = 256
  18. # Number of samples to train on.
  19. num_samples = 10000
  20. # Path to the data txt file on disk.
  21. data_path = 'fra-eng/fra.txt'
  22. # Vectorize the data.
  23. input_texts = []
  24. target_texts = []
  25. # Set方便去重
  26. input_characters = set()
  27. target_characters = set()
  28. with open(data_path, 'r', encoding='utf-8') as f:
  29. lines = f.read().split('\n')
  30. for line in lines[: min(num_samples, len(lines) - 1)]:
  31. input_text, target_text, _ = line.split('\t')
  32. # 句子开始符:\t 句子终止符:\n
  33. # We use "tab" as the "start sequence" character
  34. # for the targets, and "\n" as "end sequence" character.
  35. target_text = '\t' + target_text + '\n'
  36. input_texts.append(input_text)
  37. target_texts.append(target_text)
  38. for char in input_text:
  39. if char not in input_characters:
  40. input_characters.add(char)
  41. for char in target_text:
  42. if char not in target_characters:
  43. target_characters.add(char)
  44. # 将字符排序
  45. input_characters = sorted(list(input_characters))
  46. target_characters = sorted(list(target_characters))
  47. # Encoder的输入类别长度:字符表长度
  48. # Decoder的输出类别长度:字符表长度
  49. num_encoder_tokens = len(input_characters)
  50. num_decoder_tokens = len(target_characters)
  51. # Encoder的输入最大长度:最长的句子的长度
  52. # Decoder的输入最大长度:最长的句子的长度
  53. max_encoder_seq_length = max([len(txt) for txt in input_texts])
  54. max_decoder_seq_length = max([len(txt) for txt in target_texts])
  55. print('Number of samples:', len(input_texts))
  56. print('Number of unique input tokens:', num_encoder_tokens)
  57. print('Number of unique output tokens:', num_decoder_tokens)
  58. print('Max sequence length for inputs:', max_encoder_seq_length)
  59. print('Max sequence length for outputs:', max_decoder_seq_length)
  60. # 为每个字符与下标组成一个字典
  61. input_token_index = dict(
  62. [(char, i) for i, char in enumerate(input_characters)])
  63. target_token_index = dict(
  64. [(char, i) for i, char in enumerate(target_characters)])
  65. # 初始化Encoder输入矩阵
  66. # 第一维为句子条数,即RNN循环次数
  67. # 第二维为Encoder最大输入长度
  68. # 第三维为Encoder的输入类别长度
  69. encoder_input_data = np.zeros(
  70. (len(input_texts), max_encoder_seq_length, num_encoder_tokens),
  71. dtype='float32')
  72. # 初始化Decoder输入矩阵(Encoder输出)
  73. # 第一维为句子条数,即RNN循环次数
  74. # 第二维为Decoder最大输入长度
  75. # 第三维为Decoder的输入类别长度
  76. decoder_input_data = np.zeros(
  77. (len(input_texts), max_decoder_seq_length, num_decoder_tokens),
  78. dtype='float32')
  79. # 初始化Decoder输出矩阵
  80. # 第一维为句子条数,即RNN循环次数
  81. # 第二维为Decoder最大输入长度
  82. # 第三维为Decoder的输入类别长度
  83. decoder_target_data = np.zeros(
  84. (len(input_texts), max_decoder_seq_length, num_decoder_tokens),
  85. dtype='float32')
  86. # 将input和target打包成一对,如[input, target]
  87. for i, (input_text, target_text) in enumerate(zip(input_texts, target_texts)):
  88. for t, char in enumerate(input_text):
  89. encoder_input_data[i, t, input_token_index[char]] = 1.
  90. encoder_input_data[i, t + 1:, input_token_index[' ']] = 1.
  91. for t, char in enumerate(target_text):
  92. # decoder_target_data is ahead of decoder_input_data by one timestep
  93. decoder_input_data[i, t, target_token_index[char]] = 1.
  94. if t > 0:
  95. # decoder_target_data will be ahead by one timestep
  96. # and will not include the start character.
  97. decoder_target_data[i, t - 1, target_token_index[char]] = 1.
  98. decoder_input_data[i, t + 1:, target_token_index[' ']] = 1.
  99. decoder_target_data[i, t:, target_token_index[' ']] = 1.
  100. # Define an input sequence and process it.
  101. encoder_inputs = Input(shape=(None, num_encoder_tokens))
  102. encoder = LSTM(latent_dim, return_state=True)
  103. encoder_outputs, state_h, state_c = encoder(encoder_inputs)
  104. # We discard `encoder_outputs` and only keep the states.
  105. encoder_states = [state_h, state_c]
  106. # Set up the decoder, using `encoder_states` as initial state.
  107. decoder_inputs = Input(shape=(None, num_decoder_tokens))
  108. # We set up our decoder to return full output sequences,
  109. # and to return internal states as well. We don't use the
  110. # return states in the training model, but we will use them in inference.
  111. decoder_lstm = LSTM(latent_dim, return_sequences=True, return_state=True)
  112. decoder_outputs, _, _ = decoder_lstm(decoder_inputs,
  113. initial_state=encoder_states)
  114. decoder_dense = Dense(num_decoder_tokens, activation='softmax')
  115. decoder_outputs = decoder_dense(decoder_outputs)
  116. # Define the model that will turn
  117. # `encoder_input_data` & `decoder_input_data` into `decoder_target_data`
  118. model = Model([encoder_inputs, decoder_inputs], decoder_outputs)
  119. # Run training
  120. model.compile(optimizer='rmsprop', loss='categorical_crossentropy',
  121. metrics=['accuracy'])
  122. model.fit([encoder_input_data, decoder_input_data], decoder_target_data,
  123. batch_size=batch_size,
  124. epochs=epochs,
  125. validation_split=0.2)
  126. # Save model
  127. model.save('s2s.h5')
  128. # Next: inference mode (sampling).
  129. # Here's the drill:
  130. # 1) encode input and retrieve initial decoder state
  131. # 2) run one step of decoder with this initial state
  132. # and a "start of sequence" token as target.
  133. # Output will be the next target token
  134. # 3) Repeat with the current target token and current states
  135. # Define sampling models
  136. encoder_model = Model(encoder_inputs, encoder_states)
  137. decoder_state_input_h = Input(shape=(latent_dim,))
  138. decoder_state_input_c = Input(shape=(latent_dim,))
  139. decoder_states_inputs = [decoder_state_input_h, decoder_state_input_c]
  140. decoder_outputs, state_h, state_c = decoder_lstm(
  141. decoder_inputs, initial_state=decoder_states_inputs)
  142. decoder_states = [state_h, state_c]
  143. decoder_outputs = decoder_dense(decoder_outputs)
  144. decoder_model = Model(
  145. [decoder_inputs] + decoder_states_inputs,
  146. [decoder_outputs] + decoder_states)
  147. # Reverse-lookup token index to decode sequences back to
  148. # something readable.
  149. reverse_input_char_index = dict(
  150. (i, char) for char, i in input_token_index.items())
  151. reverse_target_char_index = dict(
  152. (i, char) for char, i in target_token_index.items())
  153. def decode_sequence(input_seq):
  154. # Encode the input as state vectors.
  155. states_value = encoder_model.predict(input_seq)
  156. # Generate empty target sequence of length 1.
  157. target_seq = np.zeros((1, 1, num_decoder_tokens))
  158. # Populate the first character of target sequence with the start character.
  159. target_seq[0, 0, target_token_index['\t']] = 1.
  160. # Sampling loop for a batch of sequences
  161. # (to simplify, here we assume a batch of size 1).
  162. stop_condition = False
  163. decoded_sentence = ''
  164. while not stop_condition:
  165. output_tokens, h, c = decoder_model.predict(
  166. [target_seq] + states_value)
  167. # Sample a token
  168. sampled_token_index = np.argmax(output_tokens[0, -1, :])
  169. sampled_char = reverse_target_char_index[sampled_token_index]
  170. decoded_sentence += sampled_char
  171. # Exit condition: either hit max length
  172. # or find stop character.
  173. if (sampled_char == '\n' or
  174. len(decoded_sentence) > max_decoder_seq_length):
  175. stop_condition = True
  176. # Update the target sequence (of length 1).
  177. target_seq = np.zeros((1, 1, num_decoder_tokens))
  178. target_seq[0, 0, sampled_token_index] = 1.
  179. # Update states
  180. states_value = [h, c]
  181. return decoded_sentence
  182. for seq_index in range(100):
  183. # Take one sequence (part of the training set)
  184. # for trying out decoding.
  185. input_seq = encoder_input_data[seq_index: seq_index + 1]
  186. decoded_sentence = decode_sequence(input_seq)
  187. print('-')
  188. print('Input sentence:', input_texts[seq_index])
  189. print('Decoded sentence:', decoded_sentence)
  190. def getBiLSTM_Dropout():
  191. '''
  192. @summary: 获得模型
  193. '''
  194. input_shape = (2, 35, 128)
  195. # input_shape = (1, 70, 128)
  196. output_shape = [5]
  197. L_input = layers.Input(shape=input_shape[1:], dtype="float32")
  198. R_input = layers.Input(shape=input_shape[1:], dtype="float32")
  199. lstm_0 = layers.Bidirectional(layers.LSTM(32, dropout=0.5, recurrent_dropout=0.5, return_sequences=True))(L_input)
  200. avg_0 = layers.GlobalAveragePooling1D()(lstm_0)
  201. lstm_2 = layers.Bidirectional(layers.LSTM(32, dropout=0.5, recurrent_dropout=0.5, return_sequences=True))(R_input)
  202. avg_2 = layers.GlobalAveragePooling1D()(lstm_2)
  203. concat = layers.merge([avg_0, avg_2], mode="concat")
  204. output = layers.Dense(output_shape[0], activation="softmax")(concat)
  205. model = models.Model(inputs=[L_input, R_input], outputs=output)
  206. model.compile(optimizer=optimizers.Adam(lr=0.0005), loss=losses.binary_crossentropy, metrics=[precision, recall, f1_score])
  207. return model
  208. def getBiRNN_Dropout():
  209. '''
  210. @summary: 获得模型
  211. '''
  212. input_shape = (2, 10, 128)
  213. output_shape = [5]
  214. L_input = layers.Input(shape=input_shape[1:], dtype="float32")
  215. R_input = layers.Input(shape=input_shape[1:], dtype="float32")
  216. lstm_0 = layers.Bidirectional(layers.SimpleRNN(32, dropout=0.65, recurrent_dropout=0.65, return_sequences=True))(L_input)
  217. avg_0 = layers.GlobalAveragePooling1D()(lstm_0)
  218. lstm_2 = layers.Bidirectional(layers.SimpleRNN(32, dropout=0.65, recurrent_dropout=0.65, return_sequences=True))(R_input)
  219. avg_2 = layers.GlobalAveragePooling1D()(lstm_2)
  220. concat = layers.merge([avg_0, avg_2], mode="concat")
  221. output = layers.Dense(output_shape[0], activation="softmax")(concat)
  222. model = models.Model(inputs=[L_input, R_input], outputs=output)
  223. model.compile(optimizer=optimizers.Adam(lr=0.0005), loss=losses.binary_crossentropy, metrics=[precision, recall, f1_score])
  224. return model
  225. def getBiGRU_Dropout():
  226. '''
  227. @summary: 获得模型
  228. '''
  229. input_shape = (2, 35, 128)
  230. # input_shape = (1, 70, 128)
  231. output_shape = [5]
  232. L_input = layers.Input(shape=input_shape[1:], dtype="float32")
  233. R_input = layers.Input(shape=input_shape[1:], dtype="float32")
  234. lstm_0 = layers.Bidirectional(layers.GRU(32, dropout=0.4, recurrent_dropout=0.4, return_sequences=True))(L_input)
  235. avg_0 = layers.GlobalAveragePooling1D()(lstm_0)
  236. lstm_2 = layers.Bidirectional(layers.GRU(32, dropout=0.4, recurrent_dropout=0.4, return_sequences=True))(R_input)
  237. avg_2 = layers.GlobalAveragePooling1D()(lstm_2)
  238. concat = layers.merge([avg_0, avg_2], mode="concat")
  239. output = layers.Dense(output_shape[0], activation="softmax")(concat)
  240. model = models.Model(inputs=[L_input, R_input], outputs=output)
  241. model.compile(optimizer=optimizers.Adam(lr=0.0005), loss=losses.binary_crossentropy, metrics=[precision, recall, f1_score])
  242. return model
  243. def getLSTM_Dropout():
  244. '''
  245. @summary: 获得模型
  246. '''
  247. input_shape = (2, 10, 128)
  248. output_shape = [5]
  249. input = layers.Input(shape=input_shape[1:], dtype="float32")
  250. lstm = layers.LSTM(32, dropout=0.2, recurrent_dropout=0.2, return_sequences=True)(input)
  251. avg = layers.GlobalAveragePooling1D()(lstm)
  252. output = layers.Dense(output_shape[0], activation="softmax")(avg)
  253. model = models.Model(inputs=input, outputs=output)
  254. model.compile(optimizer=optimizers.Adam(lr=0.0005), loss=losses.binary_crossentropy, metrics=[precision, recall, f1_score])
  255. return model
  256. def getGRUModel_Dropout():
  257. '''
  258. @summary: 获得模型
  259. '''
  260. # input_shape = (2, 10, 128)
  261. input_shape = (1, 70, 128)
  262. output_shape = [5]
  263. input = layers.Input(shape=input_shape[1:], dtype="float32")
  264. gru = layers.GRU(32, dropout=0.15, recurrent_dropout=0.15, return_sequences=True)(input)
  265. avg = layers.GlobalAveragePooling1D()(gru)
  266. output = layers.Dense(output_shape[0], activation="softmax")(avg)
  267. model = models.Model(inputs=input, outputs=output)
  268. model.compile(optimizer=optimizers.Adam(lr=0.0005), loss=losses.binary_crossentropy, metrics=[precision, recall, f1_score])
  269. return model
  270. def getRNNModel_Dropout():
  271. '''
  272. @summary: 获得模型
  273. '''
  274. input_shape = (2, 10, 128)
  275. output_shape = [5]
  276. input = layers.Input(shape=input_shape[1:], dtype="float32")
  277. rnn = layers.SimpleRNN(32, dropout=0.5, recurrent_dropout=0.5, return_sequences=True)(input)
  278. avg = layers.GlobalAveragePooling1D()(rnn)
  279. output = layers.Dense(output_shape[0], activation="softmax")(avg)
  280. model = models.Model(inputs=input, outputs=output)
  281. model.compile(optimizer=optimizers.Adam(lr=0.0005), loss=losses.binary_crossentropy, metrics=[precision, recall, f1_score])
  282. return model
  283. def getGCNModel():
  284. return
  285. def getData3(isTrain = True):
  286. '''
  287. :return:返回训练数据或测试数据的词嵌入,分前后两个句子,不包含中心词
  288. '''
  289. df = pd.read_csv("C:\\Users\\admin\\Desktop\\Person_Sentence_Notest.csv")
  290. df1 = pd.read_csv("C:\\Users\\admin\\Desktop\\test2000.csv")
  291. test_data_len = df.shape[0] * 0.2
  292. if isTrain:
  293. test_data_len = 0
  294. else:
  295. test_data_len = 3700
  296. df = df1
  297. df = df.reset_index()
  298. input_shape = (2, 35, 128)
  299. output_shape = [5]
  300. allLimit = 250000
  301. all = 0
  302. data_x = []
  303. data_y = []
  304. data_context = []
  305. for index, row in df.iterrows():
  306. if isTrain:
  307. if index < test_data_len:
  308. continue
  309. else:
  310. if index >= test_data_len:
  311. break
  312. if all >= allLimit:
  313. break
  314. tokens_list_front = []
  315. tokens_list_behind = []
  316. tokens_list_all = []
  317. sss = row["Sentence"].split("||")
  318. front = sss[0]
  319. behind = sss[2]
  320. ss_front = front.split(" ")
  321. ss_behind = behind.split(" ")
  322. for s in ss_front:
  323. tokens_list_front.append(s)
  324. for s in ss_behind:
  325. tokens_list_behind.append(s)
  326. tokens_list_all.append(tokens_list_front)
  327. tokens_list_all.append(tokens_list_behind)
  328. # print(np.array(tokens_list_all).shape)
  329. item_x = embedding(tokens_list_all, shape=input_shape)
  330. item_y = np.zeros(output_shape)
  331. item_y[row[3]] = 1
  332. all += 1
  333. data_x.append(item_x)
  334. data_y.append(item_y)
  335. print(np.array(data_x).shape, np.array(data_y).shape)
  336. return np.transpose(np.array(data_x), (1, 0, 2, 3)), np.array(data_y), data_context
  337. def getData2(isTrain = True):
  338. '''
  339. :return:返回训练数据或测试数据的词嵌入,前后连成一个句子,包含中心词
  340. '''
  341. df = pd.read_csv("C:\\Users\\admin\\Desktop\\Person_Sentence_Notest.csv")
  342. df1 = pd.read_csv("C:\\Users\\admin\\Desktop\\test2000.csv")
  343. test_data_len = df.shape[0] * 0.2
  344. if isTrain:
  345. test_data_len = 0
  346. else:
  347. test_data_len = 3700
  348. df = df1
  349. df = df.reset_index()
  350. input_shape = (1, 70, 128)
  351. output_shape = [5]
  352. allLimit = 250000
  353. all = 0
  354. data_x = []
  355. data_y = []
  356. data_context = []
  357. for index, row in df.iterrows():
  358. if isTrain:
  359. if index < test_data_len:
  360. continue
  361. else:
  362. if index >= test_data_len:
  363. break
  364. if all >= allLimit:
  365. break
  366. tokens_list = []
  367. tokens_list_all = []
  368. ss = row["Sentence"].split(" ")
  369. for s in ss:
  370. tokens_list.append(s)
  371. tokens_list_all.append(tokens_list)
  372. item_x = embedding(tokens_list_all, shape=input_shape)
  373. item_y = np.zeros(output_shape)
  374. item_y[row[3]] = 1
  375. all += 1
  376. data_x.append(item_x)
  377. data_y.append(item_y)
  378. print(np.array(data_x).shape, np.array(data_y).shape)
  379. return np.transpose(np.array(data_x), (1, 0, 2, 3)), np.array(data_y), data_context
  380. def getData(isTrain = True):
  381. '''
  382. :return:返回训练数据或测试数据的词嵌入
  383. '''
  384. df = pd.read_csv("C:\\Users\\admin\\Desktop\\Person_Sentence_Notest.csv")
  385. df1 = pd.read_csv("C:\\Users\\admin\\Desktop\\test2000.csv")
  386. test_data_len = df.shape[0] * 0.2
  387. if isTrain:
  388. test_data_len = 0
  389. else:
  390. test_data_len = 3700
  391. df = df1
  392. df = df.reset_index()
  393. input_shape = (2, 35, 128)
  394. output_shape = [5]
  395. allLimit = 250000
  396. all = 0
  397. data_x = []
  398. data_y = []
  399. data_context = []
  400. for index, row in df.iterrows():
  401. if isTrain:
  402. if index < test_data_len:
  403. continue
  404. else:
  405. if index >= test_data_len:
  406. break
  407. if all >= allLimit:
  408. break
  409. print(np.array(spanWindow(tokens=row["Sentence"], begin_index=row["begin_index"], end_index=row["end_index"], size=input_shape[1])).shape)
  410. item_x = embedding(spanWindow(tokens=row["Sentence"], begin_index=row["begin_index"], end_index=row["end_index"], size=input_shape[1]), shape=input_shape)
  411. item_y = np.zeros(output_shape)
  412. item_y[row[3]] = 1
  413. all += 1
  414. data_x.append(item_x)
  415. data_y.append(item_y)
  416. print(np.array(data_x).shape, np.array(data_y).shape)
  417. # print(data_x, data_y, data_context)
  418. return np.transpose(np.array(data_x), (1, 0, 2, 3)), np.array(data_y), data_context
  419. def train():
  420. '''
  421. @summary: 训练模型
  422. '''
  423. model = getBiGRU_Dropout()
  424. model.summary()
  425. train_x, train_y, _ = getData3(isTrain=True)
  426. test_x, test_y, test_context = getData3(isTrain=False)
  427. # 回调checkpoint,保存loss最小的模型
  428. checkpoint = ModelCheckpoint(model_file, monitor="val_loss", verbose=1, save_best_only=True, mode='min')
  429. history_model = model.fit(x=[train_x[0], train_x[1]], y=train_y, validation_data=([test_x[0], test_x[1]], test_y), epochs=200, batch_size=256, shuffle=True, callbacks=[checkpoint])
  430. # history_model = model.fit(x=[train_x[0], train_x[0]], y=train_y, validation_data=([test_x[0], test_x[0]], test_y), class_weight='auto', epochs=100, batch_size=256, shuffle=True, callbacks=[checkpoint])
  431. # history_model = model.fit(x=[train_x[0], train_x[0]], y=train_y, validation_split=0.2, class_weight='auto', epochs=200, batch_size=256, shuffle=True, callbacks=[checkpoint])
  432. # 单向模型
  433. # history_model = model.fit(x=train_x[0], y=train_y, validation_data=([test_x[0], test_y]), class_weight='auto', epochs=200, batch_size=256, shuffle=True, callbacks=[checkpoint])
  434. # history_model = model.fit(x=train_x[0], y=train_y, validation_split=0.2, class_weight='auto', epochs=200, batch_size=256, shuffle=True, callbacks=[checkpoint])
  435. # history_model = model.fit(x=[train_x[0], train_x[1]], y=train_y, validation_split=0.2, epochs=100, class_weight='auto', batch_size=256, shuffle=True, callbacks=[checkpoint])
  436. # history_model = model.fit(x=[train_x[0], train_x[1]], y=train_y, validation_split=0.2, epochs=250, batch_size=256, shuffle=True, callbacks=[checkpoint])
  437. plotTrainTestLoss(history_model)
  438. def predict():
  439. model = models.load_model(model_file, custom_objects={'precision': precision, 'recall': recall, 'f1_score': f1_score})
  440. test_x, test_y, test_context = getData3(isTrain=False)
  441. predict_y = model.predict([test_x[0], test_x[1]])
  442. # predict_y = model.predict([test_x[0], test_x[0]])
  443. # predict_y = model.predict([test_x[0]])
  444. targets_name = ['人名', '联系人', '招标联系人', '代理联系人', '评审专家']
  445. print(classification_report(np.argmax(test_y, axis=1), np.argmax(predict_y, axis=1), target_names=targets_name))
  446. return predict_y
  447. def predict2Csv():
  448. df = pd.DataFrame(np.argmax(predict(), axis=1))
  449. df1 = pd.read_csv("C:\\Users\\admin\\Desktop\\test2000.csv")
  450. df1 = df1[0:3700]
  451. df1["predict_Label"] = df
  452. df1.to_csv("C:\\Users\\admin\\Desktop\\result3.csv")
  453. def plotTrainTestLoss(history_model):
  454. pyplot.plot(history_model.history['loss'])
  455. pyplot.plot(history_model.history['val_loss'])
  456. pyplot.title('model train vs validation loss')
  457. pyplot.ylabel('loss')
  458. pyplot.xlabel('epoch')
  459. pyplot.legend(['train', 'validation'], loc='upper right')
  460. pyplot.show()
  461. if __name__ == "__main__":
  462. # getData()
  463. train()
  464. predict()
  465. # predict2Csv()
  466. # getData3()