{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"### [MNIST digits RandomForest solver](https://www.kaggle.com/carlmcbrideellis/mnist-digits-randomforest-solver): Usage example","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19"}},{"cell_type":"code","source":"import numpy  as np\nimport pandas as pd\nimport pickle","metadata":{"execution":{"iopub.status.busy":"2022-03-12T18:47:33.366289Z","iopub.execute_input":"2022-03-12T18:47:33.367084Z","iopub.status.idle":"2022-03-12T18:47:33.394233Z","shell.execute_reply.started":"2022-03-12T18:47:33.366938Z","shell.execute_reply":"2022-03-12T18:47:33.393470Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Read in the model. \nThe model requires the input to be a numpy array of shape `(1, 784)`","metadata":{}},{"cell_type":"code","source":"RandomForest_model = pickle.load(open('../input/mnist-digits-randomforest-solver/MNIST_RandomForest_model.sav','rb'))","metadata":{"execution":{"iopub.status.busy":"2022-03-12T18:47:33.397100Z","iopub.execute_input":"2022-03-12T18:47:33.397418Z","iopub.status.idle":"2022-03-12T18:47:36.292048Z","shell.execute_reply.started":"2022-03-12T18:47:33.397386Z","shell.execute_reply":"2022-03-12T18:47:36.290872Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Usage example: Selecting a row from the [Digit Recognizer](https://www.kaggle.com/c/digit-recognizer) test dataset and returning its value:","metadata":{}},{"cell_type":"code","source":"test_df = pd.read_csv('../input/digit-recognizer/test.csv')","metadata":{"execution":{"iopub.status.busy":"2022-03-12T18:47:36.293635Z","iopub.execute_input":"2022-03-12T18:47:36.293860Z","iopub.status.idle":"2022-03-12T18:47:38.608043Z","shell.execute_reply.started":"2022-03-12T18:47:36.293832Z","shell.execute_reply":"2022-03-12T18:47:38.606869Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"row = 27996\nimage_to_classify = test_df.iloc[row,:].to_numpy().reshape(1, 784)\n\nRandomForest_model.predict(image_to_classify)[0]","metadata":{"execution":{"iopub.status.busy":"2022-03-12T18:47:38.610654Z","iopub.execute_input":"2022-03-12T18:47:38.611037Z","iopub.status.idle":"2022-03-12T18:47:38.636375Z","shell.execute_reply.started":"2022-03-12T18:47:38.610989Z","shell.execute_reply":"2022-03-12T18:47:38.635564Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Datasets\n* [The MNIST database of handwritten digits](http://yann.lecun.com/exdb/mnist/) - Yann LeCun, Corinna Cortes, and Christopher J. C. Burges\n* [MNIST digits RandomForest solver](https://www.kaggle.com/carlmcbrideellis/mnist-digits-randomforest-solver)","metadata":{}}]}