-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsvm_task.py
More file actions
32 lines (28 loc) · 872 Bytes
/
svm_task.py
File metadata and controls
32 lines (28 loc) · 872 Bytes
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
import pandas as pd
import matplotlib
import seaborn
from sklearn import svm
matplotlib.use('Agg')
if __name__ == "__main__":
data = pd.read_csv(\
'./datasets/_f6284c13db83a3074c2b987f714f24f5_svm-data.csv',
names=['target', 'A', 'B'])
S = svm.SVC(C=100000, random_state=241, kernel='linear')
svm_model = S.fit(data[['A', 'B']], data['target'])
# f = open('./svm_result.txt', 'wt')
# res = ''
# tmp = svm_model.support_
# tmp.sort()
# for i in tmp:
# res = res + str(i+1) + ','
# res = res.strip('\n')
# f.write(res)
# f.close()
with open('./svm_result.txt', 'w') as res_f:
res = ''
for i in svm_model.support_:
res = res + str(i+1) + ','
res = res.strip(',')
res_f.write(res)
plt = seaborn.regplot(data['A'], data['B'])
plt.figure.savefig('./svm.png')