{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"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\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 read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2021-06-28T10:59:18.918000Z","iopub.execute_input":"2021-06-28T10:59:18.918386Z","iopub.status.idle":"2021-06-28T10:59:18.927768Z","shell.execute_reply.started":"2021-06-28T10:59:18.918354Z","shell.execute_reply":"2021-06-28T10:59:18.926422Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.neural_network import MLPClassifier\nimport pandas as pd\nimport matplotlib.pyplot as plt","metadata":{"execution":{"iopub.status.busy":"2021-06-28T10:59:18.930110Z","iopub.execute_input":"2021-06-28T10:59:18.930518Z","iopub.status.idle":"2021-06-28T10:59:20.056013Z","shell.execute_reply.started":"2021-06-28T10:59:18.930482Z","shell.execute_reply":"2021-06-28T10:59:20.054948Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data = pd.read_csv('/kaggle/input/digit-recognizer/train.csv')\ntest_data = pd.read_csv('/kaggle/input/digit-recognizer/test.csv')\ntrain_data.head()","metadata":{"execution":{"iopub.status.busy":"2021-06-28T10:59:20.057653Z","iopub.execute_input":"2021-06-28T10:59:20.058112Z","iopub.status.idle":"2021-06-28T10:59:26.039150Z","shell.execute_reply.started":"2021-06-28T10:59:20.058061Z","shell.execute_reply":"2021-06-28T10:59:26.037835Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train = train_data.drop('label', axis=1)\ny_train = train_data['label']\n\nX_test = test_data","metadata":{"execution":{"iopub.status.busy":"2021-06-28T10:59:33.134704Z","iopub.execute_input":"2021-06-28T10:59:33.135056Z","iopub.status.idle":"2021-06-28T10:59:33.245569Z","shell.execute_reply.started":"2021-06-28T10:59:33.135027Z","shell.execute_reply":"2021-06-28T10:59:33.244456Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train = X_train.to_numpy()\ny_train = y_train.to_numpy()\n\nX_test = X_test.to_numpy()","metadata":{"execution":{"iopub.status.busy":"2021-06-28T10:59:52.032362Z","iopub.execute_input":"2021-06-28T10:59:52.032764Z","iopub.status.idle":"2021-06-28T10:59:52.037482Z","shell.execute_reply.started":"2021-06-28T10:59:52.032732Z","shell.execute_reply":"2021-06-28T10:59:52.036719Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train = X_train.reshape((-1,28,28))\nX_test = X_test.reshape((-1, 28,28))","metadata":{"execution":{"iopub.status.busy":"2021-06-28T11:00:02.865445Z","iopub.execute_input":"2021-06-28T11:00:02.865999Z","iopub.status.idle":"2021-06-28T11:00:02.870192Z","shell.execute_reply.started":"2021-06-28T11:00:02.865963Z","shell.execute_reply":"2021-06-28T11:00:02.869350Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in range(9):\n    plt.subplot(3,3,i+1)\n    plt.imshow(X_train[i])\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2021-06-28T11:00:14.366931Z","iopub.execute_input":"2021-06-28T11:00:14.367303Z","iopub.status.idle":"2021-06-28T11:00:15.195626Z","shell.execute_reply.started":"2021-06-28T11:00:14.367272Z","shell.execute_reply":"2021-06-28T11:00:15.194613Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train = X_train.reshape((-1,28*28))\nX_test = X_test.reshape((-1, 28*28))","metadata":{"execution":{"iopub.status.busy":"2021-06-28T11:00:28.738946Z","iopub.execute_input":"2021-06-28T11:00:28.739307Z","iopub.status.idle":"2021-06-28T11:00:28.746933Z","shell.execute_reply.started":"2021-06-28T11:00:28.739279Z","shell.execute_reply":"2021-06-28T11:00:28.745490Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train = X_train/256\nX_test = X_test/256","metadata":{"execution":{"iopub.status.busy":"2021-06-28T11:00:39.975085Z","iopub.execute_input":"2021-06-28T11:00:39.975434Z","iopub.status.idle":"2021-06-28T11:00:40.180639Z","shell.execute_reply.started":"2021-06-28T11:00:39.975405Z","shell.execute_reply":"2021-06-28T11:00:40.179754Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = MLPClassifier(solver='adam', activation='relu', hidden_layer_sizes = (64,64), early_stopping=True, verbose=True)\nmodel.fit(X_train, y_train)","metadata":{"execution":{"iopub.status.busy":"2021-06-28T11:00:51.309194Z","iopub.execute_input":"2021-06-28T11:00:51.309774Z","iopub.status.idle":"2021-06-28T11:01:30.438799Z","shell.execute_reply.started":"2021-06-28T11:00:51.309741Z","shell.execute_reply":"2021-06-28T11:01:30.437546Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred = model.predict(X_test)","metadata":{"execution":{"iopub.status.busy":"2021-06-28T11:01:30.441121Z","iopub.execute_input":"2021-06-28T11:01:30.441859Z","iopub.status.idle":"2021-06-28T11:01:30.606577Z","shell.execute_reply.started":"2021-06-28T11:01:30.441802Z","shell.execute_reply":"2021-06-28T11:01:30.605130Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample = pd.read_csv('/kaggle/input/digit-recognizer/sample_submission.csv')\nsubmit = pd.DataFrame()\nsubmit['ImageId'] = sample['ImageId']\nsubmit['label'] = pred\n\nsubmit.to_csv('Submission.csv', index=False)","metadata":{"execution":{"iopub.status.busy":"2021-06-28T11:01:30.608497Z","iopub.execute_input":"2021-06-28T11:01:30.609335Z","iopub.status.idle":"2021-06-28T11:01:30.742434Z","shell.execute_reply.started":"2021-06-28T11:01:30.609280Z","shell.execute_reply":"2021-06-28T11:01:30.741501Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}