-
Notifications
You must be signed in to change notification settings - Fork 0
/
__main__.py
67 lines (49 loc) · 2.23 KB
/
__main__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import warnings
warnings.simplefilter(action='ignore', category=FutureWarning)
import argparse
import logging
import sys
from sklearn.svm import OneClassSVM
from scipy.stats import uniform
from flod.classifiers.bsvclassifier import BSVClassifier
from experiments.baseline import compute_baseline, get_datasets
logger = logging.getLogger(__name__)
logger.addHandler(logging.StreamHandler(sys.stdout))
# create the parser object
parser = argparse.ArgumentParser(
description='Run the experiments from the paper.')
# add arguments to the parser
parser.add_argument('experiment', type=str, choices=[
'baseline_sklearn', 'baseline_svdd'], help='The experiment to run.')
parser.add_argument('--njobs', type=int,
help='Number of parallel threads to use.', default=-1)
parser.add_argument('--log_level', type=str, choices=['DEBUG', 'INFO', 'WARNING',
'ERROR', 'CRITICAL'], help='The logging level.', dest='loglevel', default='INFO')
parser.add_argument('dataset', type=str, choices=get_datasets().keys(), help='The dataset to run the experiment on.')
# parse the arguments
args = parser.parse_args()
def baseline_sklearn():
logger.info('Running baseline sklearn experiment on %s', args.dataset)
classifier = OneClassSVM(kernel='rbf')
distributions = dict(nu=uniform(loc=0.2, scale=0.8),
gamma=uniform(loc=0, scale=3))
auc_df, avg_df = compute_baseline('sklearn_auc.csv', 'sklearn_avg.csv', classifier, distributions, args.dataset, args.njobs)
print('AUC')
print(auc_df)
print('Average Precision')
print(avg_df)
def baseline_svdd():
logger.info('Running baseline svdd experiment on %s', args.dataset)
classifier = BSVClassifier(normal_class_label=1, outlier_class_label=-1)
distributions = {'c':uniform(loc=0.2, scale=0.8),'q':uniform(loc=0, scale=3)}
auc_df, avg_df = compute_baseline('svdd_auc.csv', 'svdd_avg.csv', classifier, distributions, args.dataset, args.njobs)
print('AUC')
print(auc_df)
print('Average Precision')
print(avg_df)
if args.loglevel:
logger.setLevel(args.loglevel)
if args.experiment == 'baseline_sklearn':
baseline_sklearn()
elif args.experiment == 'baseline_svdd':
baseline_svdd()