{"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)\nimport matplotlib.pyplot as plt, matplotlib.image as mpimg\nfrom sklearn.model_selection import train_test_split\nfrom sklearn import svm\n%matplotlib inline\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":"d189bb933a0f9aa57d448f1a04306d7921447840"},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","trusted":true,"scrolled":false},"cell_type":"code","source":"labeled_images = pd.read_csv('../input/train.csv')\nimages = labeled_images.iloc[0:5000, 1:]\nlabels = labeled_images.iloc[0:5000, :1]\ntrain_images, test_images, train_labels, test_labels = train_test_split(images, labels, train_size = 0.8, random_state = 0)\n\ni = 1\nimg = train_images.iloc[i].as_matrix()\nimg = img.reshape((28, 28))\nplt.imshow(img, cmap = 'gray')\nplt.title(train_labels.iloc[i, 0])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"8c81c5050716c2d5ee9ec2a23ce91abb9a7a8f65"},"cell_type":"code","source":"plt.hist(train_images.iloc[i])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"c8c1a7a5770edba1853cdb80c890b5320461a000"},"cell_type":"code","source":"clf = svm.SVC(gamma = 'auto')\nclf.fit(train_images, train_labels.values.ravel())\nclf.score(test_images, test_labels)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"6dfe9a0cb681b0034be7dfe2f16271791650b6cf"},"cell_type":"code","source":"test_images[test_images>0] = 1\ntrain_images[train_images>0] = 1\n\nimg = train_images.iloc[i].as_matrix().reshape((28, 28))\nplt.imshow(img, cmap = 'binary')\nplt.title(train_labels.iloc[i])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"2abcc61de03252428ecca287ea08d877e2e412a2"},"cell_type":"code","source":"plt.hist(train_images.iloc[i])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"96652e1590c2ce564566246677d7b546891722ef"},"cell_type":"code","source":"clf = svm.SVC(gamma='auto')\nclf.fit(train_images, train_labels.values.ravel())\nclf.score(test_images, test_labels)","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"142e3268b810cc0b34796ac23c5944a39919d63e","trusted":true},"cell_type":"code","source":"test_data = pd.read_csv('../input/test.csv')\ntest_data[test_data>0] = 1\nresults = clf.predict(test_data[0:5000])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"1fdbaeffddaced96e06b4c5aae1bfcd392e3d883"},"cell_type":"code","source":"results","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"fa28b605db0fd261b0bdbd865a3ecf5fe41c15fd"},"cell_type":"code","source":"df = pd.DataFrame(results)\ndf.index.name = 'ImageID'\ndf.index += 1\ndf.columns = ['Label']\ndf.to_csv('results.csv', header = True)","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}