Skip to content

Instantly share code, notes, and snippets.

@LarryStanley
Created June 28, 2017 06:57
Show Gist options
  • Save LarryStanley/3f96e6cb97b75fcfca557bb869181774 to your computer and use it in GitHub Desktop.
Save LarryStanley/3f96e6cb97b75fcfca557bb869181774 to your computer and use it in GitHub Desktop.
nn
from sklearn.neural_network import MLPClassifier
X = []
y = []
with open('letter-recognition.data') as f:
lines = f.readlines()
for line in lines:
line = line.replace("\n", "")
parseLine = line.split(",")
y.append(parseLine[0])
parseLine.pop(0)
parseLine = list(map(int, parseLine))
X.append(parseLine)
clf = MLPClassifier(solver='lbfgs', hidden_layer_sizes=(500, ), random_state=1, activation='identity', max_iter=5000, learning_rate='adaptive')
print(clf.fit(X[:15999], y[:15999]))
test_data_x = clf.predict(X[16000:19999])
test_data_y = y[16000:19999]
accuracy = 0
for index,test_x in enumerate(test_data_x):
if test_x == test_data_y[index]:
accuracy = accuracy + 1
print(accuracy/len(test_data_y))
print(clf.predict([[4,4,4,6,2,7,7,14,2,5,6,8,6,8,0,8]]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment