-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
41 lines (32 loc) · 1.43 KB
/
Copy pathmain.py
File metadata and controls
41 lines (32 loc) · 1.43 KB
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
import data_processing
import ocr
def score(list_a, list_b):
"""Computes the score"""
if not len(list_a) == len(list_b): raise Exception("Dimension mismatch")
return sum(ea == eb for ea, eb in zip(list_a, list_b)) / len(list_a)
def main():
# Load Data and split in test and train set
words = data_processing.read_PA3Data()
train_words = words[:80]
test_words = words[80:]
# Train logistig model and load picewise model
logistig_model = data_processing.train_logreg_model(train_words)
pairwise_model = data_processing.read_PA3Models_pairwise()
# Predict test words
precition = [ocr.construct_network([l[0] for l in word], logistig_model, pairwise_model)
for word in test_words]
# Calculate Scores
print("Score for words: ", score(precition, [[l[1] for l in word] for word in test_words]))
print("Score for letters: ", score([l for word in precition for l in word],
[l[1] for word in test_words for l in word]))
##import numpy as np
##def gen_custom_pairwise(letters):
## mod = np.zeros((26,26))
## letter_pair = list(zip(letters[1:], letters[:-1]))
## for i in range(26):
## for j in range(26):
## mod[i, j] = letter_pair.count(( chr(i + ord("a")), chr(j + ord("a")) ))
## return mod + 0.1
##pairwise_model = gen_custom_pairwise([l[1] for word in test_words for l in word])
if __name__ == '__main__':
main()