-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsvmML.py
More file actions
32 lines (26 loc) · 860 Bytes
/
svmML.py
File metadata and controls
32 lines (26 loc) · 860 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
from __future__ import division
import sys
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("Read Data :", data , "Result of Prediction: ", prediction)
return prediction