-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsimpleClassifiers.py
More file actions
39 lines (33 loc) · 937 Bytes
/
Copy pathsimpleClassifiers.py
File metadata and controls
39 lines (33 loc) · 937 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
33
34
35
36
37
38
39
# Philip Tenteromano
# hw0
# 1/26/2018
def threshClassify(heightList, xThresh):
giraffes = []
for animal in heightList:
if animal > xThresh:
giraffes.append(1)
else:
giraffes.append(0)
return giraffes
# test 1
heights = [4, 3, 2, 8, 1, 12]
longNecks = threshClassify(heights, 3)
print(longNecks)
def findAccuracy(classifierOutput, trueLabels):
matches = [1 for i, j in zip(classifierOutput, trueLabels) if i == j]
return len(matches) / len(classifierOutput)
# test 2
correct = [1, 0, 1, 1, 1, 0] # used for trueLabels
correctness = findAccuracy(longNecks, correct)
print(correctness)
# passing in 2d list (2 rows by C columns)
def getTraining(fullData):
training = [[], []]
for r in range(len(fullData)):
for c in range(len(fullData[r]) // 3):
training[r].append(fullData[r][c])
return training
# test 3
data = [heights, correct]
trainingData = getTraining(data)
print(trainingData)