-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsvm.py
30 lines (21 loc) · 829 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
"""
http://scikit-learn.org/stable/modules/generated/sklearn.svm.SVC.html#sklearn.svm.SVC
"""
import pylab as pl
from sklearn import svm, metrics
import pickle
# Create a classifier: a support vector classifier
classifier = svm.SVC(gamma=0.001)
# # This was originally used to pickle the SVM for HMMs:
# classifier = svm.SVC(gamma=0.001, probability=True)
f = open("characterdata24px", "r")
trainDataX, trainDataY, testDataX, testDataY = pickle.load(f)
classifier.fit(trainDataX, trainDataY)
# To pickle the SVM classifier
svm_f = open("svm24px", "w")
pickle.dump(classifier, svm_f)
expected = testDataY
predicted = classifier.predict(testDataX)
print classifier.score(testDataX, testDataY)
print("Classification report for classifier %s:\n%s\n"
% (classifier, metrics.classification_report(expected, predicted)))