Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. from sklearn.neural_network import MLPClassifier
  2.  
  3. X = []
  4. y = []
  5. with open('letter-recognition.data') as f:
  6. lines = f.readlines()
  7. for line in lines:
  8. line = line.replace("\n", "")
  9. parseLine = line.split(",")
  10. y.append(parseLine[0])
  11. parseLine.pop(0)
  12. parseLine = list(map(int, parseLine))
  13. X.append(parseLine)
  14.  
  15.  
  16. clf = MLPClassifier(solver='lbfgs', hidden_layer_sizes=(500, ), random_state=1, activation='identity', max_iter=5000, learning_rate='adaptive')
  17.  
  18. print(clf.fit(X[:15999], y[:15999]))
  19. test_data_x = clf.predict(X[16000:19999])
  20. test_data_y = y[16000:19999]
  21.  
  22. accuracy = 0
  23. for index,test_x in enumerate(test_data_x):
  24. if test_x == test_data_y[index]:
  25. accuracy = accuracy + 1
  26.  
  27. print(accuracy/len(test_data_y))
  28. print(clf.predict([[4,4,4,6,2,7,7,14,2,5,6,8,6,8,0,8]]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement