{"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.6.0"}},"nbformat":4,"nbformat_minor":0,"cells":[{"metadata":{"_cell_guid":"856f103f-d5d7-c356-f68f-df3ca1f3df72","_active":false,"collapsed":false},"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\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,"cell_type":"code","outputs":[]},{"metadata":{"_cell_guid":"ae2d3c6a-87b5-c45d-47e9-e6c9ee352c78","_active":false,"collapsed":false},"source":"import pandas as pd\nimport matplotlib.pyplot as plt, matplotlib.image as mpimg\nfrom sklearn.model_selection import train_test_split\nfrom sklearn import svm\n%matplotlib inline","execution_count":1,"cell_type":"code","outputs":[],"execution_state":"idle"},{"metadata":{"_cell_guid":"99ec4cb0-9e86-9f6a-ba20-0c09bc57fcc3","_active":false,"collapsed":false},"source":"labeled_images = pd.read_csv('../input/train.csv')\nimages = labeled_images.iloc[0:9000,1:]\nlabels = labeled_images.iloc[0:9000,:1]\ntrain_images, test_images,train_labels, test_labels = train_test_split(images, labels, train_size=0.8, random_state=0)","execution_count":59,"cell_type":"code","outputs":[],"execution_state":"idle"},{"metadata":{"_cell_guid":"48b856a4-f2f8-7d56-8cd9-b568c03f9dc8","_active":false,"collapsed":false},"source":"i=984\nimg=train_images.iloc[i].as_matrix()\nimg=img.reshape((28,28))\nplt.imshow(img,cmap='gray')\nplt.title(train_labels.iloc[i,0])\nprint(train_labels.iloc[i])","execution_count":45,"cell_type":"code","outputs":[],"execution_state":"idle"},{"metadata":{"_cell_guid":"832bd4fa-9ef4-5de6-2f76-e66371d456a1","_active":false,"collapsed":false},"source":"for j in range(784):\n    if (train_images.iloc[i][j]<10):\n        print(j, train_images.iloc[i][j])","execution_count":46,"cell_type":"code","outputs":[],"execution_state":"idle"},{"metadata":{"_cell_guid":"0d188662-dc10-357d-c087-8d8b817c5a7f","_active":false,"collapsed":false},"source":"plt.hist(train_images.iloc[i])","execution_count":54,"cell_type":"code","outputs":[],"execution_state":"idle"},{"metadata":{"_cell_guid":"d27c226a-3f98-0908-6475-bfff1466c6f6","_active":false,"collapsed":false},"source":"clf = svm.SVC()\nclf.fit(train_images, train_labels.values.ravel())\nclf.score(test_images,test_labels)","execution_count":60,"cell_type":"code","outputs":[],"execution_state":"idle"},{"metadata":{"_cell_guid":"d8d81c03-ea7c-28d0-abf9-5b3fa2e3fcfb","_active":false,"collapsed":false},"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":56,"cell_type":"code","outputs":[],"execution_state":"idle"},{"metadata":{"_cell_guid":"b4dca19e-0566-e07c-dc26-85c384f4dc9c","_active":false,"collapsed":false},"source":"plt.hist(train_images.iloc[i])","execution_count":57,"cell_type":"code","outputs":[],"execution_state":"idle"},{"metadata":{"_cell_guid":"1580a56e-bdf7-de2a-90a3-64dac2323515","_active":false,"collapsed":false},"source":"for j in range(784):\n    if (train_images.iloc[i][j]>0.5):\n        print(j, train_images.iloc[i][j])","execution_count":51,"cell_type":"code","outputs":[],"execution_state":"idle"},{"metadata":{"_cell_guid":"96650fa3-0e8e-4339-9d7c-2f5ee1c6c38a","_active":false,"collapsed":false},"source":"clf = svm.SVC()\nclf.fit(train_images, train_labels.values.ravel())\nclf.score(test_images,test_labels)","execution_count":58,"cell_type":"code","outputs":[],"execution_state":"idle"}]}