-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexperiment21_SVM.py
83 lines (69 loc) · 2.66 KB
/
experiment21_SVM.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import csm
import numpy as np
import helper as h
from tqdm import tqdm
import multiprocessing
from csm import OOB, UOB, SampleWeightedMetaEstimator, Dumb, MDET, SEA, StratifiedBagging
from strlearn.evaluators import TestThenTrain
from sklearn.naive_bayes import GaussianNB
from strlearn.metrics import (
balanced_accuracy_score,
f1_score,
geometric_mean_score_1,
precision,
recall,
specificity
)
import sys
from sklearn.base import clone
from sklearn.tree import DecisionTreeClassifier
from skmultiflow.trees import HoeffdingTree
from sklearn.neighbors import KNeighborsClassifier
from sklearn.svm import SVC
if len(sys.argv) != 2:
print("PODAJ RS")
exit()
else:
random_state = int(sys.argv[1])
print(random_state)
# Select streams and methods
streams = h.toystreams(random_state)
print(len(streams))
none_knorau1 = SEA(base_estimator=StratifiedBagging(base_estimator=SVC(
probability=True, random_state=42), random_state=42, oversampler="None"), oversampled="None", des="KNORAU1")
ros_knorau1 = SEA(base_estimator=StratifiedBagging(base_estimator=SVC(
probability=True, random_state=42), random_state=42, oversampler="ROS"), oversampled="ROS", des="KNORAU1")
b2_knorau1 = SEA(base_estimator=StratifiedBagging(base_estimator=SVC(
probability=True, random_state=42), random_state=42, oversampler="B2"), oversampled="B2", des="KNORAU1")
none_knorae1 = SEA(base_estimator=StratifiedBagging(base_estimator=SVC(
probability=True, random_state=42), random_state=42, oversampler="None"), oversampled="None", des="KNORAE1")
ros_knorae1 = SEA(base_estimator=StratifiedBagging(base_estimator=SVC(
probability=True, random_state=42), random_state=42, oversampler="ROS"), oversampled="ROS", des="KNORAE1")
b2_knorae1 = SEA(base_estimator=StratifiedBagging(base_estimator=SVC(
probability=True, random_state=42), random_state=42, oversampler = "B2"), oversampled="B2" ,des="KNORAE1")
clfs = (none_knorau1, ros_knorau1, b2_knorau1, none_knorae1, ros_knorae1, b2_knorae1)
# Define worker
def worker(i, stream_n):
stream = streams[stream_n]
cclfs = [clone(clf) for clf in clfs]
print("Starting stream %i/%i" % (i + 1, len(streams)))
eval = TestThenTrain(metrics=(
balanced_accuracy_score,
geometric_mean_score_1,
f1_score,
precision,
recall,
specificity
))
eval.process(
stream,
cclfs
)
print("Done stream %i/%i" % (i + 1, len(streams)))
results = eval.scores
np.save("results/experiment21_SVM/%s" % stream, results)
jobs = []
for i, stream_n in enumerate(streams):
p = multiprocessing.Process(target=worker, args=(i, stream_n))
jobs.append(p)
p.start()