You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
869 B

  1. from sklearn.neural_network import MLPClassifier
  2. from skimage import io
  3. img1 = io.imread("imgs/25.png")
  4. img2 = io.imread("imgs/24.png")
  5. img3 = io.imread("imgs/104.png")
  6. img4 = io.imread("otherimgs/image_0008.jpg")
  7. data_train = [img1, img2, img3, img4]
  8. data_labels = [1, 1, 1, 0]
  9. data_test = [img4, img3]
  10. clf = MLPClassifier(solver='lbfgs', alpha=1e-5,
  11. hidden_layer_sizes=(5,2), random_state=1)
  12. clf.fit(data_train, data_labels)
  13. clf.predict(data_test)
  14. print "MPLClassifier values:"
  15. [coef.shape for coef in clf.coefs_]
  16. '''
  17. images_and_predictions = list(zip(digits.images[n_samples // 2:], predicted))
  18. for index, (image, prediction) in enumerate(images_and_predictions[:4]):
  19. plt.subplot(2, 4, index + 5)
  20. plt.axis('off')
  21. plt.imshow(image, cmap=plt.cm.gray_r, interpolation='nearest')
  22. plt.title('Prediction: %i' % prediction)
  23. '''