{"cells":[{"metadata":{"collapsed":true,"_uuid":"f42e051c4770f8518b2d4ccf512ac59632c9c932","_cell_guid":"10d0d139-c5bd-4852-a31a-2987dd2f3e45","trusted":false},"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 matplotlib.pyplot as plt\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\nfrom subprocess import check_output\nprint(check_output([\"ls\", \"../input\"]).decode(\"utf8\"))\n\n# Any results you write to the current directory are saved as output.","execution_count":null,"outputs":[]},{"metadata":{"collapsed":true,"_uuid":"2a6cb0385aaaebdaed40037ee9e6502b584e26b2","_cell_guid":"af6bcf3c-12a1-431e-8bf0-459e809ecb4b","trusted":false},"cell_type":"code","source":"train = pd.read_csv('../input/train.csv')\ntrain.head()","execution_count":null,"outputs":[]},{"metadata":{"collapsed":true,"_uuid":"8516d77cce2066f7977b3da62909fe33131ea1d7","_cell_guid":"7f247290-296b-496f-a0c6-aa98ad8b7d79","trusted":false},"cell_type":"code","source":"test = pd.read_csv('../input/test.csv')\ntest.head()","execution_count":null,"outputs":[]},{"metadata":{"collapsed":true,"_uuid":"c79e8e657baf13a2bd9cd36d09feca04ee871de4","_cell_guid":"00b7ad00-9376-473b-a759-6aeb2f99a39a","trusted":false},"cell_type":"code","source":"X_train = train.iloc[:, 1:784].values\nX_train[0:5]","execution_count":null,"outputs":[]},{"metadata":{"collapsed":true,"_uuid":"7726808c5569717565833154b92073c5d0012d8f","_cell_guid":"8f6cc01e-ec38-428b-ade1-f236070c6542","trusted":false},"cell_type":"code","source":"X_test = test.iloc[:, 1:784].values\nX_test[0:5]","execution_count":null,"outputs":[]},{"metadata":{"collapsed":true,"_uuid":"03fbd1d74ce7c81f436032cac12ad43786fd0f9f","_cell_guid":"8ce0bcf6-f304-4dba-ad42-6798efc6db18","trusted":false},"cell_type":"code","source":"y_train = train.iloc[:, 0].values\ny_train[0:5]","execution_count":null,"outputs":[]},{"metadata":{"collapsed":true,"_uuid":"2929a02b16342b223d1a1bdb657665f66d0e1940","_cell_guid":"cdcac341-0db9-4bde-95e0-a03bd12b1bed","trusted":false},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"collapsed":true,"_uuid":"00671c0e4e6e88369199ea39622ec02cc80a8357","_cell_guid":"c4b694be-1f70-4386-994e-8f28fbce1bf0","trusted":false},"cell_type":"code","source":"# Feature Scaling\n#from sklearn.preprocessing import StandardScaler\n#sc = StandardScaler()\n#X_train = sc.fit_transform(X_train)\n#X_test = sc.transform(X_test)\n\n# Fitting Logistic Regression to the Training set\nfrom sklearn.tree import DecisionTreeClassifier\nclassifier = DecisionTreeClassifier()\nclassifier.fit(X_train, y_train)\n\n# Predicting the Test set results\ny_pred = classifier.predict(X_test)","execution_count":null,"outputs":[]},{"metadata":{"collapsed":true,"_uuid":"5e5a4ab62bf3d55f67030330bc02058d6a8aa753","_cell_guid":"3c4d1156-d1b5-4158-aa3a-5b43fb3023e6","trusted":false},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"collapsed":true,"_uuid":"6f7f3f89702600dcd59641a91be2205ad7ab8551","_cell_guid":"dde9c6d0-21b0-497e-b203-198b8ac2862b","trusted":false},"cell_type":"code","source":"# Making the Confusion Matrix\n#from sklearn.metrics import confusion_matrix\n#cm = confusion_matrix(y_test, y_pred)\n#plt.show()","execution_count":null,"outputs":[]},{"metadata":{"collapsed":true,"_uuid":"b25c030e74fa5a017df9a6b1d29b9090b43f9ece","_cell_guid":"35df0975-2847-441b-a8c8-6acf5047b487","trusted":false},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"collapsed":true,"_uuid":"b60ab2d97069be4e4dd2972535690287e7d3f9c8","_cell_guid":"0bcfdab5-a7c2-42a8-8748-3fe1242fce8e","trusted":false},"cell_type":"code","source":"#print(\"ImageId,Label\")\n#n = 0\n#for i in y_pred :\n#    print(n,\",\",i)\n#    n+=1\n","execution_count":null,"outputs":[]},{"metadata":{"collapsed":true,"_uuid":"277e8e7db3ad7cc51a6c4da901a89ebf24a4bb3e","_cell_guid":"09135919-927a-4e03-9718-e895bd741d04","trusted":false},"cell_type":"code","source":"output_file = \"submission.csv\"\nwith open(output_file, 'w') as f :\n    f.write('ImageId,Label\\n')\n    for i in range(len(y_pred)) :\n        f.write(\"\".join([str(i+1),',',str(y_pred[i]),'\\n']))","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"99247463-cc84-47f5-a271-ad04179012d4","collapsed":true,"_uuid":"a37e8da7225ba3c0105de1ad0114a7b94c8a7a02","trusted":false},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"collapsed":true,"_uuid":"7e93594446db3c0bacec4f55f9f3d0a3c0a1bf3e","_cell_guid":"97ee84b8-c548-4f6c-ade9-0cdf1f77728f","trusted":false},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"collapsed":true,"_uuid":"49e35b68a4670fec7031ec1a724418568a7efc39","_cell_guid":"9e78f80f-ac39-40b5-b08e-2f190a061640","trusted":false},"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.4","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"nbformat":4,"nbformat_minor":1}