{"cells":[{"metadata":{"_uuid":"044ab78e83007660cef32413d32e9e2a1db0601d"},"cell_type":"markdown","source":"#### Importing libraries"},{"metadata":{"trusted":true,"_uuid":"96273c9da9920dbbca90e29e5c50da0679cd0b5d"},"cell_type":"code","source":"%%time\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport matplotlib.pyplot as plt #for plotting\nimport seaborn as sns\n%matplotlib inline\n","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"15cbcdb78fb8b574dc63424ef75dbe69cfe5a324"},"cell_type":"markdown","source":"#### Loading Test  and training dataset"},{"metadata":{"trusted":true,"_uuid":"ae0787e43cb956d87df3617ba761618b36ad7cf7"},"cell_type":"code","source":"%%time\ntrain=pd.read_csv('../input/train.csv')\ntest=pd.read_csv('../input/test.csv')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"5ea12cbb0c3381feee4ea13969b906bab8ff81af"},"cell_type":"code","source":"train.head(5)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"414b50d010dcfe67b714c56108c093d40aaf9a59"},"cell_type":"code","source":"train.shape","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"018ab282599ea36257b8916347c15e1da154ccbd"},"cell_type":"code","source":"train.columns","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"b5aeb15c2af8ec1dd47d1246952ca07c024d2046"},"cell_type":"markdown","source":"#### Training data target label"},{"metadata":{"trusted":true,"_uuid":"a33fcbe5e261f2e4fc94943cc0cb9d22f5c9e6e1"},"cell_type":"code","source":"sns.countplot(train['label'])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"9bc15e70182e7e802d2e97d9c29b220e66dc3450"},"cell_type":"code","source":"x_train=(train.ix[:,1:].values).astype('float32')\ny_train=(train.ix[:,0].values).astype('int32')","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"5f3630ef4c30bb655a3495aa5b48823ddd0974e8"},"cell_type":"markdown","source":"#### Visualization of training set inputs images"},{"metadata":{"trusted":true,"_uuid":"9935c34ab626ed0b6a017711b268afba7dda0233"},"cell_type":"code","source":"\n# preview the images first\nplt.figure(figsize=(12,10))\nx,y=10,3\nfor i in range(30):  \n    plt.subplot(y, x, i+1)\n    plt.imshow(x_train[i].reshape((28,28)),interpolation='nearest')\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"cf134e2ace082aa2a45ae3a36fd68e8d1452abac"},"cell_type":"markdown","source":"### Test data"},{"metadata":{"trusted":true,"_uuid":"ebae33b988a7146721d20302edf6e4e1a3aad22b"},"cell_type":"code","source":"test=(test.values).astype('float32')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"28bff09b7ae17adec2949efc95de52fde8c3d1d7"},"cell_type":"code","source":"test.shape","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"1b1b410fbe73fe76d0ea12a8beab9cb595804e3a"},"cell_type":"markdown","source":"#### Visualization of test set inputs images"},{"metadata":{"trusted":true,"_uuid":"81820687bcc8d893578545f0abf696450eaeaea8"},"cell_type":"code","source":"\n# preview the images first\nplt.figure(figsize=(12,10))\nx,y=10,3\nfor i in range(30):  \n    plt.subplot(y, x, i+1)\n    plt.imshow(test[i].reshape((28,28)),interpolation='nearest')\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"33f499c1c5f31ca3ddfa1cda02fe806c9ebb371a"},"cell_type":"markdown","source":"### Neural_network  model"},{"metadata":{"trusted":true,"_uuid":"eac5f3e53e40de3c34b6d2e69258fa7575fdc50d"},"cell_type":"code","source":"%%time\nfrom sklearn.neural_network import MLPClassifier","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"a53990a564dfe5b5a2d9ab688a3e3ac15f38be67"},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"b8c71b509a9e1ca3bc0e643c5e64553a8334c54c","scrolled":true},"cell_type":"code","source":"%%time\nclf = MLPClassifier()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"8e13943c3a013bf45e4e2218622b97d0b07ee211","_kg_hide-input":true,"_kg_hide-output":true},"cell_type":"code","source":"%%time\nclf.fit(x_train, y_train)","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"26fabb049b6ca821c2136a72438622cf62d2ea94"},"cell_type":"markdown","source":"#### Prediction"},{"metadata":{"trusted":true,"_uuid":"dacbe2dcaff9c3b201d56350a1324e9e300efec9"},"cell_type":"code","source":"output=clf.predict(test)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"c7178955c9f474447184d1c36708bc49b7d40d7c"},"cell_type":"code","source":"d={\"ImageId\": list(range(1,len(output)+1)),\n                         \"Label\": output}\n","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"7821c612f25bcc21a0e1f8b2008fc17639644ed3"},"cell_type":"markdown","source":"#### Submission"},{"metadata":{"trusted":true,"_uuid":"9dca8290b0b7ea270d1de47993cf4d1480afb7d7"},"cell_type":"code","source":"sub=pd.DataFrame(d)\nsub.to_csv('Submission_digit.csv',index=False)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"aecae74ae0e965238b3fe1303fce9354dfde1ac5"},"cell_type":"code","source":"","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"name":"python","version":"3.6.6","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"nbformat":4,"nbformat_minor":1}