delimiter=',') # Generate abnormal data abnormal_data = adg.generate_abnormal_data_from_raw_data(overwrite_data=False, generate_graph=True, show_graph=False) abnormal_data = abnormal_data[:, 1:] abnormal_ratios = [] for i in range(results_array.shape[0]): print('======================== Iteration {} ========================'. format(i)) ae_tests_score, ae_tests_scores = aeu.test_trained_ae_model( test_data=abnormal_data, model_dir_path=trained_model_path, iteration_number=i) # Refer to the deep_ae_summary_results.csv threshold_value = results_array['threshold_value'][i] abnormal_ratio = sum( [score > threshold_value for score in ae_tests_scores]) / float(len(ae_tests_scores)) abnormal_ratios.append(abnormal_ratio) output_string = '\n{0:.2f}% of abnormal samples are detected as abnormal.'.format( abnormal_ratio * 100.0) print(output_string) print('==============================================================')
hidden_units=best_layer_type) autoencoder.train(train_data=train_data, save_model=True, test_saved_model=True, model_dir_path=saved_ae_network_path, iteration_number=i, print_and_plot_history=True, show_plots=False) # Get the scores ae_train_score = autoencoder.global_mse ae_train_scores = autoencoder.mse_per_sample ae_validate_score, ae_validate_scores = aeu.test_trained_ae_model( test_data=validation_data, model_dir_path=saved_ae_network_path, iteration_number=i) ae_tests_score, ae_tests_scores = aeu.test_trained_ae_model( test_data=abnormal_data, model_dir_path=saved_ae_network_path, iteration_number=i) # Format the test scores: [Iteration, Test_sample_No, Score] if i == 0: with open(os.path.join(data.dir_name, test_score_filename), 'wb') as score_file: score_file.write(b'iteration,test_sample_no,score\n') rows_number = len(ae_tests_scores) test_scores_array = np.hstack((np.full(