{"cells": [{"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", "\n", "import numpy as np # linear algebra\n", "import 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", "\n", "from subprocess import check_output\n", "print(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": {"trusted": false, "_cell_guid": "7f9dd247-7068-0826-2aaa-deded25c24c7", "_uuid": "5bfa01fd0f66ef81a8b0dc10bfeca15f646b4966"}}, {"cell_type": "code", "source": "import matplotlib.pyplot as plt\nimport sklearn\n", "execution_count": null, "outputs": [], "metadata": {"trusted": false, "_cell_guid": "a168ec43-bff6-e94a-36ac-d322e0166692", "_uuid": "017b99d10e8289c561bf5043f023fa258872daad"}}, {"cell_type": "code", "source": "data = pd.read_csv('../input/train.csv')", "execution_count": null, "outputs": [], "metadata": {"trusted": false, "_cell_guid": "5cba6159-94ce-576c-b64c-875c69cc771e", "_uuid": "f66618299fcf1a2a9a19c96224b3f5c842e06ad6"}}, {"cell_type": "code", "source": "a = data.iloc[0,1:].values", "execution_count": null, "outputs": [], "metadata": {"trusted": false, "_cell_guid": "154203a6-2a17-53be-cebc-58bddefbebfc", "_uuid": "160b049568f0eed160012e5d38ec28aea87f8b2d"}}, {"cell_type": "code", "source": "a", "execution_count": null, "outputs": [], "metadata": {"trusted": false, "_cell_guid": "7288bb23-12fc-3e76-7278-94d834b8744a", "_uuid": "8d0d0132f3f236682d166a91089fe088e018394e"}}, {"cell_type": "code", "source": "a = a.reshape(28,28).astype('uint8')", "execution_count": null, "outputs": [], "metadata": {"trusted": false, "_cell_guid": "2aa0fec8-6a37-86a3-76ed-27c6f616c51a", "_uuid": "bfaa402dff0e6be576978dbb273e515d0c8de190"}}, {"cell_type": "code", "source": "a", "execution_count": null, "outputs": [], "metadata": {"trusted": false, "_cell_guid": "31e6f469-be73-0f0f-71b9-309d513c280d", "_uuid": "312aab16765e271cad601f62a1303335a9fbdc60"}}, {"cell_type": "code", "source": "%matplotlib inline\nplt.imshow(a)", "execution_count": null, "outputs": [], "metadata": {"trusted": false, "_cell_guid": "02292012-8529-8b42-f0ce-7f4646bbf11b", "_uuid": "8ec29626ca82e6d70c29ff9afee9c440f978ff69"}}, {"cell_type": "code", "source": "data_x = data.iloc[:,1:]\ndata_y = data.iloc[:,0]", "execution_count": null, "outputs": [], "metadata": {"trusted": false, "_cell_guid": "3b522a6a-ad5f-9454-eb25-cd2c7b361511", "_uuid": "ecc0f07fb9815ec1797e9bf4c24f2c327367a8b6"}}, {"cell_type": "code", "source": "data_y", "execution_count": null, "outputs": [], "metadata": {"trusted": false, "_cell_guid": "df88b19b-9945-ac48-4c79-8f0bfc7d3934", "_uuid": "2262106ffb3b980ae5c9d7eb45191e1e49e65b05"}}, {"cell_type": "code", "source": "from sklearn.ensemble import RandomForestClassifier", "execution_count": null, "outputs": [], "metadata": {"trusted": false, "_cell_guid": "e4638db1-438d-bd42-980f-795ecb5dd539", "_uuid": "2a2207219ebb3f283344fab825ef676adb14870b"}}, {"cell_type": "code", "source": "model = RandomForestClassifier(n_estimators = 90)\nmodel.fit(data_x,data_y)", "execution_count": null, "outputs": [], "metadata": {"trusted": false, "_cell_guid": "80418add-330e-db18-8659-e694790cb15d", "_uuid": "cdd19715347f58d0ed37eed8268dbfb191737d55"}}, {"cell_type": "code", "source": "test = pd.read_csv('../input/test.csv')", "execution_count": null, "outputs": [], "metadata": {"trusted": false, "_cell_guid": "a355555f-c5ed-21d1-5dcb-95fff48bd9c3", "_uuid": "3d8b1dd496003abcfa60a5e94421a936721b9790"}}, {"cell_type": "code", "source": "ab = model.predict(data_x)", "execution_count": null, "outputs": [], "metadata": {"trusted": false, "_cell_guid": "6745888c-2480-e89a-09df-b16b9c6ae5c6", "_uuid": "4e7cdfa3dc372c2bcf65006b1721e07ce87bfea4"}}, {"cell_type": "code", "source": "var = 0\nfor i in range(0,42000):\n        if ab[i] == data_y[i]:\n                             var = var + 1             \n                \n                ", "execution_count": null, "outputs": [], "metadata": {"trusted": false, "_cell_guid": "9bcda9b1-5de4-7577-1aa2-846983c73226", "_uuid": "c6c6201984996a1e120480a9759ff0cd6967222a"}}, {"cell_type": "code", "source": "var", "execution_count": null, "outputs": [], "metadata": {"trusted": false, "_cell_guid": "5b88af47-1b50-0f98-a517-757c5d53c351", "_uuid": "58e5d92d88446fe17cf79a46475a91e5dd85b519"}}, {"cell_type": "code", "source": "ab = model.predict(test)", "execution_count": null, "outputs": [], "metadata": {"trusted": false, "_cell_guid": "ad523037-8ce2-1940-83e9-01a2769c8fab", "_uuid": "c9a42dc826566d0d554671d99889579204a8b18f"}}, {"cell_type": "code", "source": "import caffe", "execution_count": null, "outputs": [], "metadata": {"trusted": false, "_cell_guid": "fe79ec32-3d28-8ff4-fcf8-04c32d8ee3b5", "_execution_state": "idle", "_uuid": "de4b7bb4bbb8a316902f7978a332eed1402de19f"}}, {"cell_type": "code", "source": ["ggle"], "execution_count": null, "outputs": [], "metadata": {"trusted": false, "_cell_guid": "b3d903b9-3092-47d6-1408-c7d60959e2a4", "_uuid": "04b91ba4e3b974121eba7950b0db243ed3e68895"}}, {"cell_type": "code", "source": "np.savetxt(\"file_name.csv\", ab, delimiter=\",\", fmt='%s', header='label')", "execution_count": null, "outputs": [], "metadata": {"trusted": false, "_cell_guid": "8866e024-f646-c2ae-3091-757b7139af25", "_uuid": "bc68d4a9a0aa83a3f47ecdb23a342286c1cb376d"}}, {"cell_type": "code", "source": "print(check_output([\"ls\", \"../input\"]).decode(\"utf8\"))", "execution_count": null, "outputs": [], "metadata": {"trusted": false, "_cell_guid": "e6d220f9-4314-b611-4c97-b868568778d5", "_uuid": "b82304e7f2ad9d2d063f4696f021c4ee4e5b161c"}}, {"cell_type": "code", "source": "", "execution_count": null, "outputs": [], "metadata": {"trusted": false, "_cell_guid": "1a61ae2c-97e4-c705-1881-4aa33db1b20d", "_uuid": "3e11e91893adae50ea542de3ff8adaf82d9492b4"}}], "metadata": {"_is_fork": false, "language_info": {"version": "3.6.1", "name": "python", "pygments_lexer": "ipython3", "codemirror_mode": {"version": 3, "name": "ipython"}, "mimetype": "text/x-python", "file_extension": ".py", "nbconvert_exporter": "python"}, "kernelspec": {"name": "python3", "language": "python", "display_name": "Python 3"}, "_change_revision": 0}, "nbformat_minor": 0, "nbformat": 4}