{"cells":[{"metadata":{"_cell_guid":"ec0ecec6-68a6-458a-94c9-c422f1b347a9","_uuid":"496977f2a9c6e4ffaebc9287d06ffe7d6d900308"},"cell_type":"markdown","source":"Based on \"A Beginner's Approach to Classification\" by [Charlie H][1]\n[1]:https://www.kaggle.com/archaeocharlie\n"},{"metadata":{"_cell_guid":"284840d7-f0df-4c48-81f8-c5cffc7a171d","_uuid":"759e66ed9541b6fd4916717d24f5016428ad32b0","trusted":true,"collapsed":true},"cell_type":"code","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\n","execution_count":3,"outputs":[]},{"metadata":{"scrolled":true,"_cell_guid":"5c7e4acf-f84d-41c4-81ce-66ac69fa5383","_uuid":"b7b2e818babee35c798df2c14666270fc379c986","trusted":true},"cell_type":"code","source":"#Loading the data.Just 1000 images for a short test\nlabeled_images = pd.read_csv('../input/train.csv')\nimages = labeled_images.iloc[0:10000,1:]\nlabels = labeled_images.iloc[0:10000,:1]\n#Setup of the necessary variables for training an testing the network\ntrain_images, test_images,train_labels, test_labels = train_test_split(images, labels, train_size=0.8, random_state=0)\n\n","execution_count":4,"outputs":[]},{"metadata":{"_cell_guid":"439f33ab-6722-423e-a315-c1db825a452b","_uuid":"c6b0f33a9132132c35e9590c28d433578ed1d2a0","trusted":true},"cell_type":"code","source":"#black and white\ntest_images[test_images>0]=1\ntrain_images[train_images>0]=1\ni=23\nimg=train_images.iloc[i].as_matrix().reshape((28,28))\nplt.imshow(img,cmap='binary')\nplt.title(train_labels.iloc[i])\n","execution_count":5,"outputs":[]},{"metadata":{"_cell_guid":"e0b64876-cc33-4ed8-8cdf-3d67eaea5dd7","_uuid":"7e37ef5a941923097600c2b376a805bee3a13239","trusted":true},"cell_type":"code","source":"#train. The result should be better\nclf = svm.SVC()\nclf.fit(train_images, train_labels.values.ravel())\nclf.score(test_images,test_labels)\n\n#submission\nsubmission = pd.concat([pd.Series(range(1,28001),name = \"ImageId\"),test_images],axis = 1)\nsubmission.to_csv(\"submission.csv\",index=False)\n\n","execution_count":10,"outputs":[]},{"metadata":{"_kg_hide-input":true,"_uuid":"56262598785a06c86fd432ac941040eed81872d7","_cell_guid":"ba809712-7e6c-4465-8ad4-b2a62111f0cb","collapsed":true,"_kg_hide-output":true},"cell_type":"markdown","source":""}],"metadata":{"language_info":{"name":"python","version":"3.6.5","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"}},"nbformat":4,"nbformat_minor":1}