{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load in \n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the \"../input/\" directory.\n# For example, running this (by clicking run or pressing Shift+Enter) will list the files in the input directory\n\nimport os\nprint(os.listdir(\"../input\"))\n\n# Any results you write to the current directory are saved as output.","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"f5de501d2417e0531515566b81abaeeab1abda23"},"cell_type":"code","source":"import matplotlib.pyplot as plt\nfrom sklearn.datasets import load_digits","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","trusted":true,"scrolled":true},"cell_type":"code","source":"df_train = pd.read_csv(\"../input/train.csv\")\ndf_test = pd.read_csv(\"../input/test.csv\")\ndf_train.columns","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"67a516756fbb9532065e7a52315c755275ee886e"},"cell_type":"code","source":"df_train.isnull().any().sum()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"eccf21f03896b41b3f23652131836d503f26d311"},"cell_type":"code","source":"df_test.isnull().any().sum()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"scrolled":false,"_uuid":"80f8cc93d3ce67227f3f0c8d79ef46fd8900a556"},"cell_type":"code","source":"df_train.head()\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"1e7174e2a45d5559af7e781b177e43685f060f9e"},"cell_type":"code","source":"b = df_train.iloc[1,1:].values\nc = np.reshape(b,(1,784))\nc\ndf_train.iloc[1,1:].values\n\n#c[0][1:65]\n#np.reshape(c[0][1:65],(1,64))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"dab5ebbaaabbea2be9fa69c30f06da1b2b4ef1e5"},"cell_type":"code","source":"import pylab as pl\na = df_train.iloc[1,1:].values\npl.figure(figsize = (6,6))\npl.gray()\nplt.subplot(1,1,1)\nplt.imshow(np.reshape(df_train.iloc[1,1:].values,(28,28)), cmap = plt.cm.gray_r, interpolation = 'nearest')\nplt.subplot(1,1,1)\nplt.imshow(np.reshape(df_train.iloc[2,1:].values,(28,28)), cmap = plt.cm.gray_r, interpolation = 'nearest')\n#pl.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"d5ea8dfa7de8af3993874d780d351ee9251bb69c"},"cell_type":"code","source":"df_train['label'].shape\ndf_train.tail()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"scrolled":true,"_uuid":"496beb9ec084eb9832e54453fcd7b633b3a905e2"},"cell_type":"code","source":"from sklearn import ensemble\nclassifier  = ensemble.RandomForestClassifier()\ny = df_train['label']\nx = [df_train.iloc[i,1:].values for i in range(42000)]\nclassifier.fit(x,y)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"39ebfb9075730687f81e1bc6928078287217bae5"},"cell_type":"code","source":"df_test.tail()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"9b9da41088c9914c63a9b7333b8a8084f1baa9a0"},"cell_type":"code","source":"submission = pd.read_csv('../input/sample_submission.csv')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"b02a7f615ad9c405c1924cc05e4a673943b66bef"},"cell_type":"code","source":"submission.head()\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"dd02dbf6b3eb21689d966459e21809be9df3a409"},"cell_type":"code","source":"submission.iloc[70,1]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"scrolled":true,"_uuid":"b998ae2dc396d8f9cb8a62f8719ec5458c067908"},"cell_type":"code","source":"#yt = df_test['label']\n#xt = [df_test.iloc[i,1:].values for i in range(2800)]\n\nfor i in range(28000):    \n    submission.iloc[i,1] = classifier.predict(df_test.iloc[i,0:].values.reshape(1,784))[0]\n#classifier.predict(df_test.iloc[1,0:].values.reshape(1,784))\n#df_test.iloc[1,0:].values","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"5897839aa39ab062c7bbd8dd4476ada8d0311847"},"cell_type":"code","source":"import cv2\ndictio = {0:'predicted :0 ',1:'predicted : 1',2:'predicted : 2',3:'predicted : 3',4:'predicted : 4',5:'predicted : 5',6:'predicted : 6',7:'predicted : 7',8:'predicted : 8',9:'predicted : 9'}\nfig, axes = plt.subplots(4, 4, figsize = (15,15))\nfor row in axes:\n    for axe in row:\n        index = np.random.randint(len(submission))\n        axe.imshow(np.reshape(df_test.iloc[index,0:].values,(28,28)))\n        key = classifier.predict(df_test.iloc[index,0:].values.reshape(1,784))[0]\n        axe.set_title(dictio[key])\n        axe.set_axis_off()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"b0e240aca260a531ff39339ef9a21ee8e136857d"},"cell_type":"code","source":"submission.to_csv(\"subm.csv\", index = False)","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}