Advertisement
Guest User

Untitled

a guest
May 23rd, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.88 KB | None | 0 0
  1. ######################################################
  2. x, y = pickle.load(open('train.pkl', 'rb'))
  3.  
  4. x_hist = np.zeros((x.shape[0], 36))
  5. for i, row in enumerate(x):
  6.     hist, _ = np.histogram(row, bins=36)
  7.     x_hist[i] = hist
  8.  
  9. ######################################################
  10. x_train = x_hist[0:10000]
  11. y_train = y[0:10000]
  12.  
  13. x_val = x_hist[10000:12500]
  14. y_val = y[10000:12500]
  15. ######################################################
  16.  
  17. mlp = MLP(n_features=x_train.shape[1], n_hidden=50, n_output=10,
  18.           eta=0.001, decrease_const=0.000005, l1=0.1, l2=0.1, alpha=0.001, batch_size=50)
  19.  
  20. costs = mlp.fit(x_train, y_train, epochs=1000, show_progress=True)
  21.  
  22. # validation
  23. predictions = mlp.predict(x_val)
  24. accuracy = np.sum(y_val == predictions, axis=0) / x_val.shape[0]
  25. print("Validation accuracy: %.2f" % accuracy)
  26. ######################################################
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement