In [1]:
import numpy as np
import pandas as pd
In [131]:
lines = {}
counter = 0
with open('test_input.txt', 'r') as f:
for line in f:
lines[counter] = line.replace(' \n','').replace('\n','').split(' ')
counter += 1
In [132]:
print counter
lines
Out[132]:
In [64]:
for x in xrange(len(lines[2])):
if lines[2][x] == '..':
lines[2][x] = 'a-j'
elif lines[2][x] == '.O':
lines[2][x] = 'w'
elif lines[2][x] == 'O.':
lines[2][x] = 'k-t'
elif lines[2][x] == 'OO':
lines[2][x] = 'uvxyz'
In [65]:
lines
Out[65]:
In [ ]:
In [118]:
characters = []
In [119]:
for x in xrange(len(lines[0])):
characters.append(lines[0][x] + lines[1][x] + lines[2][x])
In [120]:
characters
Out[120]:
In [85]:
from sklearn import tree
from sklearn.ensemble import RandomForestClassifier
In [121]:
characters = [x.replace('O','1').replace('.','0') for x in characters]
In [122]:
X = []
for c in characters:
X.append([int(x) for x in list(c)])
In [123]:
X
Out[123]:
In [77]:
characters = [int(x) for x in characters]
In [79]:
X = characters
In [80]:
Y = ['H', 'E', 'L', 'L', 'O', 'W', 'O', 'R', 'L', 'D']
In [93]:
Y = [8, 5, 12, 12, 15, 23, 15, 18, 12, 4]
In [124]:
clf = tree.DecisionTreeClassifier()
In [86]:
clf = RandomForestClassifier(n_estimators = 10)
In [115]:
np.array(Y)
Out[115]:
In [125]:
clf = clf.fit(X, Y)
In [126]:
clf.predict([1, 0, 1, 1, 0, 0])
Out[126]:
In [ ]:
In [161]:
import string
In [164]:
alphabet = list(string.ascii_lowercase)
In [165]:
alphabet
Out[165]:
In [166]:
X = [[1, 0, 0, 0, 0, 0], # A
[1, 0, 1, 0, 0, 0], # B
[1, 1, 0, 0, 0, 0], # C
[1, 1, 0, 1, 0, 0], # D
[1, 0, 0, 1, 0, 0], # E
[1, 1, 1, 0, 0, 0], # F
[1, 1, 1, 1, 0, 0], # G
[1, 0, 1, 1, 0, 0], # H
[0, 1, 1, 0, 0, 0], # I
[0, 1, 1, 1, 0, 0], # J
[1, 0, 0, 0, 1, 0], # K
[1, 0, 1, 0, 1, 0], # L
[1, 1, 0, 0, 1, 0], # M
[1, 1, 0, 1, 1, 0], # N
[1, 0, 0, 1, 1, 0], # O
[1, 1, 1, 0, 1, 0], # P
[1, 1, 1, 1, 1, 0], # Q
[1, 0, 1, 1, 1, 0], # R
[0, 1, 1, 0, 1, 0], # S
[0, 1, 1, 1, 1, 0], # T
[1, 0, 0, 0, 1, 1], # U
[1, 0, 1, 0, 1, 1], # V
[0, 1, 1, 1, 0, 1], # W
[1, 1, 0, 0, 1, 1], # X
[1, 1, 0, 1, 1, 1], # Y
[1, 0, 0, 1, 1, 1]] # Z
In [167]:
Y = [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]
In [173]:
clf = tree.DecisionTreeClassifier()
In [174]:
clf = clf.fit(X, Y)
In [175]:
clf.predict([1, 0, 1, 1, 0, 0])
Out[175]:
In [176]:
lines = {}
counter = 0
with open('test_input.txt', 'r') as f:
for line in f:
lines[counter] = line.replace(' \n','').replace('\n','').split(' ')
counter += 1
In [177]:
print counter
lines
Out[177]:
In [178]:
characters = []
In [179]:
for x in xrange(len(lines[0])):
characters.append(lines[0][x] + lines[1][x] + lines[2][x])
In [180]:
characters
Out[180]:
In [181]:
characters = [x.replace('O','1').replace('.','0') for x in characters]
In [182]:
characters
Out[182]:
In [183]:
X = []
for c in characters:
X.append([int(x) for x in list(c)])
In [184]:
X
Out[184]:
In [185]:
predictions = clf.predict(X)
In [186]:
predictions
Out[186]:
In [190]:
message = ""
for x in predictions:
message += alphabet[x-1]
In [191]:
message
Out[191]:
In [ ]:
In [188]:
lines = {}
counter = 0
with open('input.txt', 'r') as f:
for line in f:
lines[counter] = line.replace(' \n','').replace('\n','').split(' ')
counter += 1
In [189]:
print counter
lines
Out[189]:
In [192]:
characters = []
In [193]:
for x in xrange(len(lines[0])):
characters.append(lines[0][x] + lines[1][x] + lines[2][x])
In [194]:
characters
Out[194]:
In [195]:
characters = [x.replace('O','1').replace('.','0') for x in characters]
In [196]:
characters
Out[196]:
In [197]:
X = []
for c in characters:
X.append([int(x) for x in list(c)])
In [198]:
X
Out[198]:
In [199]:
predictions = clf.predict(X)
In [200]:
predictions
Out[200]:
In [202]:
message = ""
for x in predictions:
message += alphabet[x-1]
In [203]:
message
Out[203]: