-
Notifications
You must be signed in to change notification settings - Fork 0
/
SplitClassifier.py
53 lines (40 loc) · 1.27 KB
/
SplitClassifier.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
from Constants import *
################################################################################
# Makes very confident predictions based on linearly separating the data
def splitClassifier(filename):
file = open(filename, 'r')
lines = file.readlines()[1:]
x = []
# Read file into a list of tuples
for line in lines:
line = line.strip("\n")
line = line.split(",")
f1 = float(line[1])
f2 = float(line[2])
x.append((f1, f2))
split = findSplit(x)
predictions = []
for (f1, f2) in x:
if (f1 + f2 > split):
predictions.append(0.99)
else:
predictions.append(0.01)
return predictions
################################################################################
# Returns a sum that splits the data in half
def findSplit(xTest):
split = -2.0
# Possible infinite loop is bad...
while True:
above = 0
below = 0
for (f1, f2) in xTest:
if (f1 + f2 > split):
above += 1
else:
below += 1
if abs(above - below) < 5:
return split
else:
split += 0.0001
################################################################################