{"cells":[{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"77c70ade-5e5e-74a9-6247-f6eb604d8cb8"},"outputs":[],"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."},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"e57fc651-2f1c-971f-5d76-40344e1f3efb"},"outputs":[],"source":"df = pd.read_csv('../input/train.csv')"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"d58d7d7e-eefa-37fd-9e05-2292672a57bd"},"outputs":[],"source":"y = df.label\nX = df.ix[:, df.columns != 'label']"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"ee0c9093-2573-4313-aa45-c1dc5c483cad"},"outputs":[],"source":"from sklearn.cross_validation import train_test_split\nX_train, X_test, y_train, y_test = train_test_split(X, y)"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"ae158017-9575-91c1-ecb6-3525d3d8eccf"},"outputs":[],"source":"from sklearn.neighbors import KNeighborsClassifier\nknn = KNeighborsClassifier(n_neighbors = 5)\nknn.fit(X_train, y_train)\ny_pred = knn.predict(X_test)"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"81b07f86-d05b-9294-525c-abc83a0440bf"},"outputs":[],"source":"from sklearn.metrics import accuracy_score\naccuracy_score(y_test, y_pred) "},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"82d96151-ded8-dffe-0427-58eddedeb7b7"},"outputs":[],"source":"data = pd.read_csv('../input/test.csv')"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"0c1dc5a5-4104-d3ae-a862-7782cd7d78d9"},"outputs":[],"source":"data.head()"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"d76e197a-941d-e14b-548a-5b6c63732628"},"outputs":[],"source":"df.shape"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"f18f0d3c-a3ca-5976-9db0-09f87672cfbd"},"outputs":[],"source":"data.shape"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"fa88d2af-2925-4eec-2e01-f6164b2bd48c"},"outputs":[],"source":"X_predict = data"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"cb2d5070-c78f-e463-6efd-8d4a2a2ccc1c"},"outputs":[],"source":"y_predict = knn.predict(data)"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"bb3bbc57-bb95-d7fe-e9d4-283d17cda876"},"outputs":[],"source":"import numpy as np\nnp.savetxt('C:/Machine Learning/test_house.csv',y_predict ,delimiter=',')"}],"metadata":{"_change_revision":0,"_is_fork":false,"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}