예제 #1
0
def test_static_api():
    host = '127.0.0.1'
    user = '******'
    password = '******'
    algorithm = [
        'iforest', 'ocsvm', 'lof', 'robustcovariance', 'cblof', 'knn', 'hbos',
        'sod', 'pca', 'dagmm', 'autoencoder', 'lstm_ad', 'lstm_ed',
        'staticautoencoder'
    ]
    rng = np.random.RandomState(42)
    np.random.seed(42)
    conn, cursor = connect_server(host, user, password)
    ground_truth_whole = insert_demo_data(conn,
                                          cursor,
                                          'db',
                                          't',
                                          ground_truth_flag=True)
    data, ground_truth = query_data(conn,
                                    cursor,
                                    'db',
                                    't',
                                    time_serie_name='ts',
                                    ground_truth=ground_truth_whole,
                                    start_time='2019-07-20 00:00:00',
                                    end_time='2019-08-20 00:00:00',
                                    time_serie=False,
                                    ground_truth_flag=True)

    for alg in algorithm:
        clf = algorithm_selection(alg, random_state=rng, contamination=0.1)
        print('Start processing:')
        start_time = time.clock()
        clf.fit(data)
        prediction_result = clf.predict(data)
        outlierness = clf.decision_function(data)
        output_performance(alg, ground_truth, prediction_result,
                           time.clock() - start_time, outlierness)
    data, ground_truth = query_data(conn,
                                    cursor,
                                    'db',
                                    't',
                                    time_serie_name='ts',
                                    ground_truth=ground_truth_whole,
                                    start_time=None,
                                    end_time=None,
                                    time_serie=False,
                                    ground_truth_flag=True)
    data, ground_truth = query_data(conn,
                                    cursor,
                                    'db',
                                    't',
                                    time_serie_name='ts',
                                    ground_truth=ground_truth_whole,
                                    start_time=None,
                                    end_time=None,
                                    time_serie=False,
                                    ground_truth_flag=False)

    conn.close()
예제 #2
0
def test_io_static():
    host = '127.0.0.1'
    user = '******'
    password = '******'
    alg = 'iforest'

    rng = np.random.RandomState(42)
    np.random.seed(42)
    conn, cursor = connect_server(host, user, password)
    ground_truth_whole = insert_demo_data(conn,
                                          cursor,
                                          'db',
                                          't',
                                          ground_truth_flag=True)
    data, ground_truth = query_data(conn,
                                    cursor,
                                    'db',
                                    't',
                                    time_serie_name='ts',
                                    ground_truth=ground_truth_whole,
                                    start_time='2019-07-20 00:00:00',
                                    end_time='2019-08-20 00:00:00',
                                    time_serie=False,
                                    ground_truth_flag=True)

    clf = algorithm_selection(alg, random_state=rng, contamination=0.1)
    print('Start processing:')
    start_time = time.clock()
    clf.fit(data)
    prediction_result = clf.predict(data)
    outlierness = clf.decision_function(data)
    output_performance(alg, ground_truth, prediction_result,
                       time.clock() - start_time, outlierness)

    visualize_distribution_static(data, prediction_result, outlierness)
    visualize_distribution(data, prediction_result, outlierness)
    visualize_outlierscore(outlierness, prediction_result, contamination=0.1)

    data, ground_truth = query_data(conn,
                                    cursor,
                                    'db',
                                    't',
                                    time_serie_name='ts',
                                    ground_truth=ground_truth_whole,
                                    start_time=None,
                                    end_time='2019-08-20 00:00:00',
                                    time_serie=False,
                                    ground_truth_flag=True)
    data, ground_truth = query_data(conn,
                                    cursor,
                                    'db',
                                    't',
                                    time_serie_name='ts',
                                    ground_truth=ground_truth_whole,
                                    start_time='2019-07-20 00:00:00',
                                    end_time=None,
                                    time_serie=False,
                                    ground_truth_flag=True)
예제 #3
0
def test_timestamp_api():
    host = '127.0.0.1'
    user = '******'
    password = '******'
    algorithm = ['luminol']
    rng = np.random.RandomState(42)
    np.random.seed(42)
    conn, cursor = connect_server(host, user, password)
    ground_truth_whole = insert_demo_data(conn,
                                          cursor,
                                          'db',
                                          't',
                                          ground_truth_flag=True)
    data, ground_truth = query_data(conn,
                                    cursor,
                                    'db',
                                    't',
                                    time_serie_name='ts',
                                    ground_truth=ground_truth_whole,
                                    start_time='2019-07-20 00:00:00',
                                    end_time='2019-08-20 00:00:00',
                                    time_serie=True,
                                    ground_truth_flag=True)
    for alg in algorithm:
        clf = algorithm_selection(alg, random_state=rng, contamination=0.1)
        print('Start processing:')
        start_time = time.clock()
        clf.fit(data)
        prediction_result = clf.predict(data)
        outlierness = clf.decision_function(data)
        output_performance(alg, ground_truth, prediction_result,
                           time.clock() - start_time, outlierness)
    conn.close()
예제 #4
0
파일: demo.py 프로젝트: rajgupt/pyodds
    #read data
    print('Load dataset and table')
    start_time = time.clock()
    if args.ground_truth:
        ground_truth_whole = insert_demo_data(conn, cursor, args.database,
                                              args.table, args.ground_truth)
    else:
        insert_demo_data(conn, cursor, args.database, args.table,
                         args.ground_truth)

    if args.ground_truth:
        data, ground_truth = query_data(conn,
                                        cursor,
                                        args.database,
                                        args.table,
                                        args.start_time,
                                        args.end_time,
                                        args.time_serie_name,
                                        ground_truth_whole,
                                        time_serie=args.time_stamp,
                                        ground_truth_flag=args.ground_truth)
    else:
        data = query_data(conn,
                          cursor,
                          args.database,
                          args.table,
                          args.start_time,
                          args.end_time,
                          args.time_serie_name,
                          time_serie=args.time_stamp,
                          ground_truth_flag=args.ground_truth)