-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.py
57 lines (41 loc) · 1.85 KB
/
example.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from perceptron import PerceptronNetwork
from bayes import NaiveBayes
# The purpose of this class is to show an example of training the perceptron and naive bayes classifiers with 100% of the digit training data and testing one digit. For use during demos.
# paths
digitTrainingImagesPath = "data/digitdata/trainingimages"
digitTrainingLabelsPath = "data/digitdata/traininglabels"
faceTrainingImagesPath = "data/facedata/facedatatrain"
faceTrainingLabelsPath = "data/facedata/facedatatrainlabels"
digitWidth = 28
digitHeight = 28
digitY = list(range(0, 10))
digit = """
+#++
+####+
++######
+###+++#
+###+ +#+
+### +##
+###+ ##+
+##+ +#+
### +#+
+##+ +##+
+## +##+
+#+ +##+
+#+ +##
+#+ +#+
+##+ +##+
###+ +##+
+####++###++
+#########
++#######
+###+++
"""
digitPercep = PerceptronNetwork(digitWidth*digitHeight, digitY)
digitPercep.train(digitWidth, digitHeight, digitTrainingImagesPath, digitTrainingLabelsPath)
print "Perceptron guess:"
print digitPercep.test_one(digitWidth, digitHeight, digit)
digitBayes = NaiveBayes(digitWidth*digitHeight, 10, 2)
digitBayes.train(digitWidth, digitHeight, digitTrainingImagesPath, digitTrainingLabelsPath)
print "Naive Bayes guess:"
print digitBayes.test_one(digitWidth, digitHeight, digit)