import defaults """ Visualizes the impact of context width on anomaly detection accuracy by evaluating the accuracy of a given kNN anomaly detection problem on a single sequence. """ CONTEXT_WIDTHS = range(20, 400, 1) TEST_FILE = 'sequences/random_walk_added_noise' # set up anomaly detectors anomaly_detectors = [] ad_config = defaults.DEFAULT_KNN_CONFIG for context_width in CONTEXT_WIDTHS: ad_config['context_config'] = {'method': 'local_symmetric', 'width': context_width} anomaly_detectors.append(anomaly_detection.create_anomaly_detector(**ad_config)) # init test test = [utils.load_sequence(TEST_FILE)] test_suite = utils.TestSuite(anomaly_detectors, CONTEXT_WIDTHS, [test], ['test']) # execute test test_suite.evaluate(display_progress=True) # get plots results = test_suite.results fig1, plot1 = utils.plot_normalized_anomaly_vector_heat_map(results, CONTEXT_WIDTHS, ylabel='m') fig2, plot2 = utils.plot_mean_error_values(results, CONTEXT_WIDTHS, CONTEXT_WIDTHS, xlabel='m') fig3, plot3 = utils.plot_execution_times(results, CONTEXT_WIDTHS, CONTEXT_WIDTHS, xlabel='m')
import defaults """ Visualizes the impact of the kNN k values on anomaly detection accuracy by evaluating the accuracy of a given kNN anomaly detection problem on a single sequence. """ K_VALUES = range(1, 101, 1) TEST_FILE = 'sequences/random_walk_added_noise' # set up anomaly detectors anomaly_detectors = [] ad_config = defaults.DEFAULT_KNN_CONFIG for k_value in K_VALUES: ad_config['evaluator_config']['k'] = k_value anomaly_detectors.append(anomaly_detection.create_anomaly_detector(**ad_config)) # init test test = [utils.load_sequence(TEST_FILE)] test_suite = utils.TestSuite(anomaly_detectors, K_VALUES, [test], ['test']) # execute test test_suite.evaluate(display_progress=True) # get plots results = test_suite.results fig1, plot1 = utils.plot_normalized_anomaly_vector_heat_map(results, K_VALUES, ylabel='k') fig2, plot2 = utils.plot_mean_error_values(results, K_VALUES, K_VALUES, xlabel='k') fig3, plot3 = utils.plot_execution_times(results, K_VALUES, K_VALUES, xlabel='k')
""" Visualizes the impact of the sliding window step on anomaly detection accuracy by evaluating the accuracy of a given (sliding window) kNN anomaly detection problem on a single sequence. """ STEP_VALUES = range(1, 11, 1) TEST_FILE = 'sequences/random_walk_added_noise' # set up anomaly detectors anomaly_detectors = [] ad_config = defaults.DEFAULT_KNN_CONFIG for step_value in STEP_VALUES: filter_config = {'method': 'sliding_window', 'width': 10, 'step': step_value} ad_config['evaluation_filter_config'] = filter_config ad_config['reference_filter_config'] = filter_config anomaly_detectors.append(anomaly_detection.create_anomaly_detector(**ad_config)) # init test test = [utils.load_sequence(TEST_FILE)] test_suite = utils.TestSuite(anomaly_detectors, STEP_VALUES, [test], ['test']) # execute test test_suite.evaluate(display_progress=True) # get plots results = test_suite.results fig1, plot1 = utils.plot_normalized_anomaly_vector_heat_map(results, STEP_VALUES, ylabel='s') fig2, plot2 = utils.plot_mean_error_values(results, STEP_VALUES, STEP_VALUES, xlabel='s') fig3, plot3 = utils.plot_execution_times(results, STEP_VALUES, STEP_VALUES, xlabel='s')
filter_config = { 'method': 'sliding_window', 'width': 10, 'step': step_value } ad_config['evaluation_filter_config'] = filter_config ad_config['reference_filter_config'] = filter_config anomaly_detectors.append( anomaly_detection.create_anomaly_detector(**ad_config)) # init test test = [utils.load_sequence(TEST_FILE)] test_suite = utils.TestSuite(anomaly_detectors, STEP_VALUES, [test], ['test']) # execute test test_suite.evaluate(display_progress=True) # get plots results = test_suite.results fig1, plot1 = utils.plot_normalized_anomaly_vector_heat_map(results, STEP_VALUES, ylabel='s') fig2, plot2 = utils.plot_mean_error_values(results, STEP_VALUES, STEP_VALUES, xlabel='s') fig3, plot3 = utils.plot_execution_times(results, STEP_VALUES, STEP_VALUES, xlabel='s')
anomaly_detectors = [] ad_config = defaults.DEFAULT_KNN_CONFIG for width in WINDOW_WIDTHS: filter_config = {'method': 'sliding_window', 'width': width, 'step': 1} ad_config['evaluation_filter_config'] = filter_config ad_config['reference_filter_config'] = filter_config anomaly_detectors.append( anomaly_detection.create_anomaly_detector(**ad_config)) # init test test = [utils.load_sequence(TEST_FILE)] test_suite = utils.TestSuite(anomaly_detectors, WINDOW_WIDTHS, [test], ['test']) # execute test test_suite.evaluate(display_progress=True) # get plot results = test_suite.results fig1, plot1 = utils.plot_normalized_anomaly_vector_heat_map(results, WINDOW_WIDTHS, ylabel='w') fig2, plot2 = utils.plot_mean_error_values(results, WINDOW_WIDTHS, WINDOW_WIDTHS, xlabel='w') fig3, plot3 = utils.plot_execution_times(results, WINDOW_WIDTHS, WINDOW_WIDTHS, xlabel='w')
ad_config = defaults.DEFAULT_KNN_CONFIG for context_width in CONTEXT_WIDTHS: ad_config['context_config'] = { 'method': 'local_symmetric', 'width': context_width } anomaly_detectors.append( anomaly_detection.create_anomaly_detector(**ad_config)) # init test test = [utils.load_sequence(TEST_FILE)] test_suite = utils.TestSuite(anomaly_detectors, CONTEXT_WIDTHS, [test], ['test']) # execute test test_suite.evaluate(display_progress=True) # get plots results = test_suite.results fig1, plot1 = utils.plot_normalized_anomaly_vector_heat_map(results, CONTEXT_WIDTHS, ylabel='m') fig2, plot2 = utils.plot_mean_error_values(results, CONTEXT_WIDTHS, CONTEXT_WIDTHS, xlabel='m') fig3, plot3 = utils.plot_execution_times(results, CONTEXT_WIDTHS, CONTEXT_WIDTHS, xlabel='m')
""" Visualizes the impact of the sliding window width on anomaly detection accuracy by evaluating the accuracy of a given (sliding window) kNN anomaly detection problem on a single sequence. """ WINDOW_WIDTHS = range(1, 51, 1) TEST_FILE = 'sequences/random_walk_added_noise' # set up anomaly detectors anomaly_detectors = [] ad_config = defaults.DEFAULT_KNN_CONFIG for width in WINDOW_WIDTHS: filter_config = {'method': 'sliding_window', 'width': width, 'step': 1} ad_config['evaluation_filter_config'] = filter_config ad_config['reference_filter_config'] = filter_config anomaly_detectors.append(anomaly_detection.create_anomaly_detector(**ad_config)) # init test test = [utils.load_sequence(TEST_FILE)] test_suite = utils.TestSuite(anomaly_detectors, WINDOW_WIDTHS, [test], ['test']) # execute test test_suite.evaluate(display_progress=True) # get plot results = test_suite.results fig1, plot1 = utils.plot_normalized_anomaly_vector_heat_map(results, WINDOW_WIDTHS, ylabel='w') fig2, plot2 = utils.plot_mean_error_values(results, WINDOW_WIDTHS, WINDOW_WIDTHS, xlabel='w') fig3, plot3 = utils.plot_execution_times(results, WINDOW_WIDTHS, WINDOW_WIDTHS, xlabel='w')