-
Notifications
You must be signed in to change notification settings - Fork 1
/
MLPerceptronTest.py
37 lines (28 loc) · 1.04 KB
/
MLPerceptronTest.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
__author__ = 'mohnish'
from numpy import *
from matplotlib.pyplot import *
color_map = {1: "ro", 2: "bo", 3: "go"}
unit_step = lambda x: 0 if x < 0 else 1
data = genfromtxt(open("multiclassdatatest.csv","r"),delimiter=",", dtype="f8")[:]
def max_value_plus_index(l):
max_value = max(l)
max_value_index = l.index(max_value)
return max_value, max_value_index
weights=[[-410.,-250.],[-90.,640.],[500.,-390.]]
#weights=[[ -180., -100.],[ -60., 320.],[ 240., -220.]]
count_correct=[0,0,0]
count_incorrect=[0,0,0]
for index in xrange(len(data)):
x = data[index][:2]
expected_outcome = int(data[index][2])
results=[dot(x,w) for w in weights]
max_val,max_val_index=max_value_plus_index(results)
print expected_outcome," ",max_val_index
if max_val_index == expected_outcome-1:
count_correct[expected_outcome-1]=count_correct[expected_outcome-1]+1
else:
count_incorrect[expected_outcome-1]=count_incorrect[expected_outcome-1]+1
print count_correct
print count_incorrect
print "Correct",count_correct
print "InCorrect",count_incorrect