# print('set 1') # test_features = pickle.load(open('/mnt/shdstorage/for_classification/elmo/elmo_sent_test_v7.pkl', 'rb')) # label = pd.read_csv('/mnt/shdstorage/for_classification/test_v7.csv')['label'].values.tolist() # dtest = xgb.DMatrix(test_features) # data = model.predict(dtest) # print(data) # prediction = np.array(data) # print(prediction) # prediction = prediction >= 0.5 # prediction = prediction.astype(int) # # test_1, test_0 = calculate_all_metrics(label, prediction, 'TEST') # # print('set 2') print('Ver') ver_features = pickle.load( open('/mnt/shdstorage/for_classification/elmo/elmo_sent_ver.pkl', 'rb')) label = pd.read_csv('/mnt/shdstorage/for_classification/new_test.csv' )['negative'].values.tolist() dver = xgb.DMatrix(ver_features) data = model.predict(dver) print(data) prediction = np.array(data) print(prediction) prediction = prediction >= 0.5 prediction = prediction.astype(int) verif_1, verif_0 = calculate_all_metrics(label, prediction, 'VERIFICATION')
# ================================= MODEL SAVE ========================================= # path_to_weights = "models_dir/model_%s.h5" % (timing) path_to_weights = '/mnt/shdstorage/for_classification/models_dir/model_%s.h5' % timing path_to_architecture = "/mnt/shdstorage/for_classification/models_dir/architecture/model_%s.h5" model.save_weights(path_to_weights) model.save(path_to_architecture) print('Model is saved %s' % path_to_weights) else: timing = previous_weights.split('/')[-1].split('_')[-1].split('.')[0] score, acc = model.evaluate(X_test, y_test, batch_size=batch_size) print('Test score:', score) print('Test accuracy:', acc) train_res = model.predict_classes(X_train) train_res = [i[0] for i in train_res] train_1, train_0 = calculate_all_metrics(y_train, train_res, 'TRAIN') test_res = model.predict_classes(X_test) test_res = [i[0] for i in test_res] test_1, test_0 = calculate_all_metrics(y_test, test_res, 'TEST') ver_res = model.predict_classes(X_ver) data = pd.read_csv('/mnt/shdstorage/for_classification/new_test.csv') label = data['label'].tolist() ver_res = [i[0] for i in ver_res] verif_1, verif_0 = calculate_all_metrics(label, ver_res, 'VERIFICATION')
# ============================== PRINT METRICS ===================================== # train_res = model.predict_classes(X_train) # train_res = [i[0] for i in train_res] # train_1, train_0 = calculate_all_metrics(y_train, train_res, 'TRAIN') # # test_res = model.predict_classes(X_test) # test_res = [i[0] for i in test_res] # test_1, test_0 = calculate_all_metrics(y_test, test_res, 'TEST') ver_res = model.predict_classes(verification) path_to_verification = verification_name data = pd.read_csv(path_to_verification) label = data['negative'].tolist() ver_res = [i[0] for i in ver_res] verif_1, verif_0 = calculate_all_metrics(label, ver_res, 'VERIFICATION') # ======================= LOGS ======================= logs_name = 'logs/qrnn/%s.txt' % timing try: stream = open('logs/qrnn/%s.txt' % timing, 'r') stream.close() except: with open(logs_name, 'w') as f: f.write('======= DATASETS =======\n') f.write('Train set data: %s\n' % x_train_set_name) f.write('Test set data: %s\n' % x_test_set_name) f.write('Train labels: %s\n' % y_train_labels)