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)

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)

# for [-1,-1] # 1~10 # 0.01 ~ 1