{"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":"2022-04-01T05:19:31.585556Z","iopub.execute_input":"2022-04-01T05:19:31.586545Z","iopub.status.idle":"2022-04-01T05:19:31.595334Z","shell.execute_reply.started":"2022-04-01T05:19:31.586486Z","shell.execute_reply":"2022-04-01T05:19:31.594585Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = pd.read_csv('/kaggle/input/digit-recognizer/train.csv')\ntest = pd.read_csv('/kaggle/input/digit-recognizer/test.csv')","metadata":{"execution":{"iopub.status.busy":"2022-04-01T05:19:35.668788Z","iopub.execute_input":"2022-04-01T05:19:35.669063Z","iopub.status.idle":"2022-04-01T05:19:40.314688Z","shell.execute_reply.started":"2022-04-01T05:19:35.669025Z","shell.execute_reply":"2022-04-01T05:19:40.313979Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib as mpl\nimport matplotlib.pyplot as plt\n%matplotlib inline","metadata":{"execution":{"iopub.status.busy":"2022-04-01T05:19:48.684309Z","iopub.execute_input":"2022-04-01T05:19:48.684717Z","iopub.status.idle":"2022-04-01T05:19:48.690766Z","shell.execute_reply.started":"2022-04-01T05:19:48.684678Z","shell.execute_reply":"2022-04-01T05:19:48.690181Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_Y = train['label']\ntrain_X = train.drop('label', axis=1)","metadata":{"execution":{"iopub.status.busy":"2022-04-01T05:19:50.576637Z","iopub.execute_input":"2022-04-01T05:19:50.577164Z","iopub.status.idle":"2022-04-01T05:19:50.693985Z","shell.execute_reply.started":"2022-04-01T05:19:50.577131Z","shell.execute_reply":"2022-04-01T05:19:50.69325Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"rows = 42000\nelements = np.zeros((rows, 28, 28))\nfor i in range(rows):\n    elements[i] = train_X.loc[i].values.reshape(28, 28)","metadata":{"execution":{"iopub.status.busy":"2022-04-01T05:19:52.568583Z","iopub.execute_input":"2022-04-01T05:19:52.569111Z","iopub.status.idle":"2022-04-01T05:19:56.342573Z","shell.execute_reply.started":"2022-04-01T05:19:52.569078Z","shell.execute_reply":"2022-04-01T05:19:56.341914Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.imshow(elements[42], cmap=\"binary\")\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-04-01T05:19:58.4667Z","iopub.execute_input":"2022-04-01T05:19:58.467089Z","iopub.status.idle":"2022-04-01T05:19:58.621517Z","shell.execute_reply.started":"2022-04-01T05:19:58.467061Z","shell.execute_reply":"2022-04-01T05:19:58.620614Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from keras.models import Sequential\nfrom keras.layers import Dense, Activation\nfrom keras.layers import Conv2D, MaxPooling2D\nfrom keras.layers import Flatten","metadata":{"execution":{"iopub.status.busy":"2022-04-01T05:20:01.345336Z","iopub.execute_input":"2022-04-01T05:20:01.345818Z","iopub.status.idle":"2022-04-01T05:20:01.349291Z","shell.execute_reply.started":"2022-04-01T05:20:01.345785Z","shell.execute_reply":"2022-04-01T05:20:01.348773Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = Sequential([\n    Conv2D(32, kernel_size=(3, 3),\n           activation='relu', input_shape=(28, 28, 1)),\n    MaxPooling2D(2),\n    Conv2D(64, kernel_size=(3, 3), activation='relu'),\n    MaxPooling2D(2),\n    Conv2D(128, kernel_size=(3, 3), activation='relu'),\n    MaxPooling2D(2),\n    Flatten(),\n    Dense(10, activation='softmax')\n])","metadata":{"execution":{"iopub.status.busy":"2022-04-01T05:20:46.440279Z","iopub.execute_input":"2022-04-01T05:20:46.440964Z","iopub.status.idle":"2022-04-01T05:20:46.49086Z","shell.execute_reply.started":"2022-04-01T05:20:46.440917Z","shell.execute_reply":"2022-04-01T05:20:46.49005Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.compile(optimizer='rmsprop',\n              loss='categorical_crossentropy',\n              metrics=['accuracy'])","metadata":{"execution":{"iopub.status.busy":"2022-04-01T05:20:23.351911Z","iopub.execute_input":"2022-04-01T05:20:23.352298Z","iopub.status.idle":"2022-04-01T05:20:23.360688Z","shell.execute_reply.started":"2022-04-01T05:20:23.35227Z","shell.execute_reply":"2022-04-01T05:20:23.359882Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.fit(elements, train_Y)","metadata":{"execution":{"iopub.status.busy":"2022-04-01T05:20:26.761254Z","iopub.execute_input":"2022-04-01T05:20:26.761503Z","iopub.status.idle":"2022-04-01T05:20:27.027559Z","shell.execute_reply.started":"2022-04-01T05:20:26.761478Z","shell.execute_reply":"2022-04-01T05:20:27.026324Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}