-
Notifications
You must be signed in to change notification settings - Fork 1
/
svm.py
31 lines (25 loc) · 848 Bytes
/
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
from __future__ import division
import numpy
import os
from sklearn import svm
from collections import deque
from sklearn import tree
class SVM:
def __init__(self):
"""
train the model from generated training data in generate-data folder
"""
data = numpy.loadtxt(open('result.csv', 'rb'), delimiter=',', dtype='str')
#Support_Vector_Machine
#self.svm = svm.SVC()
# Decision tree
self.svm = tree.DecisionTreeClassifier()
self.svm.fit(data[:, 0:3], data[:, 3])
def classify(self, data):
fparams = numpy.zeros((1, 3))
fparams[:,0] = data[0]
fparams[:,1] = data[1]
fparams[:,2] = data[2]
prediction = self.svm.predict(fparams)
print("SVM input data", data , "prediction result ", prediction)
return prediction