{"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":{"_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","trusted":true},"cell_type":"code","source":"train = pd.read_csv(\"../input/train.csv\")\ntest = pd.read_csv(\"../input/test.csv\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"255c128d1f41684864ccea0c46684732849c81eb"},"cell_type":"code","source":"#train.shape\n#test.shape\n#train.head()\n#test.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"e02a315d1d76e6a1c14dedc73383253c2caa45a4"},"cell_type":"code","source":"import matplotlib.pyplot as plt\nfrom sklearn.ensemble import RandomForestClassifier\nfrom sklearn.cross_validation import train_test_split\n%matplotlib inline\n\na = train.iloc[6,1:].values\na = a.reshape(28,28).astype('uint8')\nplt.imshow(a)\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"0cf3661ab979123fc2e2f5f4078f16ec5b98ed0f"},"cell_type":"code","source":"df_x = train.iloc[:,1:] #feature values\ndf_y = train.iloc[:,0] #label values","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"9325b60bb9404c333a279eb7ba1e8d0b7c598bac"},"cell_type":"code","source":"x_train, x_test, y_train, y_test = train_test_split(df_x,df_y,test_size = 0.2,random_state=4)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"8b7a153f878769b6e92a9cba2f126406eb48813e"},"cell_type":"code","source":"rf = RandomForestClassifier(n_estimators = 100)\nrf.fit(x_train,y_train)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"59852c899896d3637cbd001509afcd47f1e6e7e6"},"cell_type":"code","source":"pred = rf.predict(x_test)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"b04ee31c51c187f7eb3f416071635128be4c567a"},"cell_type":"code","source":"y = y_test.values\ncount = 0\nfor i in range(len(pred)):\n    if pred[i] == y[i]:\n        count += 1\n\n#calculate accuracy of this model \nacc = count/len(pred)\nprint(acc)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"4c9871054cf2975d86cb316c67cba91c7b76ef8a"},"cell_type":"code","source":"X_test = test.iloc[:,:].values\nY_test = rf.predict(X_test)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"4e0a347ec5145932c87aa5df1d6912e59e08f9f9"},"cell_type":"code","source":"a = X_test[77]\na = a.reshape(28,28).astype('uint8')\nplt.imshow(a)\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"2e64d3f3af6db115ab6ecb2f38d956fb7567af27"},"cell_type":"code","source":"Y_test[77]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"208fadc3777b0ffbf0b6fba91a5fffba9dfcc18f"},"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}