Skip to content

Instantly share code, notes, and snippets.

@mianuddin
Last active March 14, 2020 23:09
Show Gist options
  • Save mianuddin/3ce7114ae98df9bf52afa700060a5a7b to your computer and use it in GitHub Desktop.
Save mianuddin/3ce7114ae98df9bf52afa700060a5a7b to your computer and use it in GitHub Desktop.
Classify MNIST with Random Forest Classifier
(import [tensorflow [keras]])
(import [numpy :as np])
(import [sklearn.ensemble [RandomForestClassifier]])
(import [sklearn.metrics [accuracy_score]])
(setv mnist keras.datasets.mnist)
(setv [[train-images train-labels] [test-images test-labels]] (.load_data mnist))
(print f"train-images: {(. train-images shape)}")
(print f"train-labels: {(. train-labels shape)}")
(print f"test-images: {(. test-images shape)}")
(print f"test-labels: {(. test-labels shape)}")
(setv trees (RandomForestClassifier))
(.fit trees (.reshape np train-images [60000, 784]) train-labels)
(print (accuracy_score test-labels
(.predict trees (.reshape np test-images [10000, 784]))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment