daily pastebin goal
29%
SHARE
TWEET

Untitled

a guest Dec 13th, 2018 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import keras
  2. import numpy as np
  3. from keras.datasets import mnist
  4. import matplotlib.pyplot as plt
  5. from sklearn.metrics import accuracy_score
  6.  
  7. (X_train, y_train), (X_test, y_test) = mnist.load_data()
  8.  
  9. print("Datasets size")
  10. print("Train data:", X_train.shape)
  11. print("Test data:", X_test.shape)
  12.  
  13. print("Samples from training data:")
  14. for i in range(0,10):
  15.     plt.subplot(1,10,i+1)
  16.     plt.imshow(X_train[i], cmap=plt.get_cmap("gray"))
  17.     plt.title(y_train[i]);
  18.     plt.axis('off');
  19. plt.show()
  20.  
  21. images_train =  []
  22. for image_train in X_train:
  23.     images_train.append(image_train.flatten())
  24.  
  25. images_test = []
  26.  
  27. for image_test in X_test:
  28.     images_test.append(image_test.flatten())
  29.  
  30. images_train = np.array(images_train)
  31. images_test = np.array(images_test)
  32.  
  33. from sklearn.neural_network import MLPClassifier
  34.  
  35. neural_network = MLPClassifier(hidden_layer_sizes=(30,20,10),random_state=1)
  36.  
  37. neural_network.fit(images_train, y_train)
  38.  
  39.  
  40.  
  41. acc = accuracy_score(y_test, neural_network.predict(images_test))
  42. print("Neural network model accuracy is {0:0.2f}".format(acc))
  43. print("Number of connection between input and first hidden layer:")
  44. print(np.size(neural_network.coefs_[0]))
  45.  
  46. print("Number of connection between first and second hidden layer:")
  47. print(np.size(neural_network.coefs_[1]))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top