-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSVM_test.py
41 lines (35 loc) · 992 Bytes
/
SVM_test.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
import csv
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn import svm
from sklearn.metrics import accuracy_score
import math
import ast
filename ="result.csv"
X = []
y = []
def sigmoid(x):
return 1 / (1 + math.exp(-x))
with open(filename) as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
fname = row['filename']
sus_b_c = row['sus_b_c']
permission = row['permission']
if len(sus_b_c) ==8: # for [-1,-1]
continue
x = ast.literal_eval(sus_b_c)
p = ast.literal_eval(permission)
label = np.array(int(row['label']))
x = [int(x) for x in x]
p = [int(p) for p in p]
X.append(x+p)
y.append(label)
X_train, X_test, y_train, y_test = train_test_split(X,y,test_size=0.33)
C = 1.0 # 1~10
gamma =1 # 0.01 ~ 1
kernel = ['linear','rbf']
clf = svm.SVC(kernel ='linear',C=C, gamma = gamma).fit(X_train,y_train)
predict = clf.predict(X_test)
score = accuracy_score(predict,y_test)
print(score)