{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":3004,"databundleVersionId":861823,"sourceType":"competition"}],"dockerImageVersionId":30746,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"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":"2024-07-19T08:35:29.215738Z","iopub.execute_input":"2024-07-19T08:35:29.216212Z","iopub.status.idle":"2024-07-19T08:35:29.224780Z","shell.execute_reply.started":"2024-07-19T08:35:29.216169Z","shell.execute_reply":"2024-07-19T08:35:29.223500Z"},"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')\nx_train = train.drop(columns=['label'])\ny_train = train.label","metadata":{"execution":{"iopub.status.busy":"2024-07-19T08:35:29.226873Z","iopub.execute_input":"2024-07-19T08:35:29.227231Z","iopub.status.idle":"2024-07-19T08:35:34.570666Z","shell.execute_reply.started":"2024-07-19T08:35:29.227200Z","shell.execute_reply":"2024-07-19T08:35:34.569331Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from keras.utils import to_categorical\n\n# Convert labels to one-hot encoded format\ny_train = to_categorical(y_train, num_classes=10)\n","metadata":{"execution":{"iopub.status.busy":"2024-07-19T08:35:34.572415Z","iopub.execute_input":"2024-07-19T08:35:34.572800Z","iopub.status.idle":"2024-07-19T08:35:34.581226Z","shell.execute_reply.started":"2024-07-19T08:35:34.572767Z","shell.execute_reply":"2024-07-19T08:35:34.579939Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import tensorflow as tf \nfrom tensorflow import keras \nimport numpy as np\nfrom tensorflow.keras.models import Sequential\nfrom tensorflow.keras.layers import Dense, Dropout","metadata":{"execution":{"iopub.status.busy":"2024-07-19T08:35:34.582693Z","iopub.execute_input":"2024-07-19T08:35:34.583040Z","iopub.status.idle":"2024-07-19T08:35:34.597414Z","shell.execute_reply.started":"2024-07-19T08:35:34.583011Z","shell.execute_reply":"2024-07-19T08:35:34.595997Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = Sequential([\n    Dense(512, activation='relu', input_shape=(784,)),\n    Dropout(0.2),\n    Dense(512, activation='relu'),\n    Dropout(0.2),\n    Dense(10, activation='softmax')\n])\n\nmodel.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])","metadata":{"execution":{"iopub.status.busy":"2024-07-19T08:35:34.600786Z","iopub.execute_input":"2024-07-19T08:35:34.601567Z","iopub.status.idle":"2024-07-19T08:35:34.658172Z","shell.execute_reply.started":"2024-07-19T08:35:34.601498Z","shell.execute_reply":"2024-07-19T08:35:34.656687Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_train.shape","metadata":{"execution":{"iopub.status.busy":"2024-07-19T08:35:34.659840Z","iopub.execute_input":"2024-07-19T08:35:34.660232Z","iopub.status.idle":"2024-07-19T08:35:34.668297Z","shell.execute_reply.started":"2024-07-19T08:35:34.660198Z","shell.execute_reply":"2024-07-19T08:35:34.666683Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.fit(x_train,y_train, epochs= 3)","metadata":{"execution":{"iopub.status.busy":"2024-07-19T08:35:34.670046Z","iopub.execute_input":"2024-07-19T08:35:34.670664Z","iopub.status.idle":"2024-07-19T08:36:05.741190Z","shell.execute_reply.started":"2024-07-19T08:35:34.670629Z","shell.execute_reply":"2024-07-19T08:36:05.740110Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"prediction = model.predict(test)","metadata":{"execution":{"iopub.status.busy":"2024-07-19T08:45:44.489062Z","iopub.execute_input":"2024-07-19T08:45:44.489850Z","iopub.status.idle":"2024-07-19T08:45:47.204114Z","shell.execute_reply.started":"2024-07-19T08:45:44.489812Z","shell.execute_reply":"2024-07-19T08:45:47.202963Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"prediction","metadata":{"execution":{"iopub.status.busy":"2024-07-19T08:45:52.184006Z","iopub.execute_input":"2024-07-19T08:45:52.184374Z","iopub.status.idle":"2024-07-19T08:45:52.192814Z","shell.execute_reply.started":"2024-07-19T08:45:52.184346Z","shell.execute_reply":"2024-07-19T08:45:52.191558Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"prediction.shape","metadata":{"execution":{"iopub.status.busy":"2024-07-19T08:49:16.744193Z","iopub.execute_input":"2024-07-19T08:49:16.744674Z","iopub.status.idle":"2024-07-19T08:49:16.752890Z","shell.execute_reply.started":"2024-07-19T08:49:16.744632Z","shell.execute_reply":"2024-07-19T08:49:16.751702Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predicted_classes = np.argmax(prediction, axis=1)\n\n# Create a DataFrame with sequential ImageId starting from 1\nsubmission_df = pd.DataFrame({\n    'ImageId': np.arange(1, len(predicted_classes) + 1),\n    'Label': predicted_classes\n})\n\n# Save the DataFrame to a CSV file\nsubmission_df.to_csv('submission.csv', index=False)","metadata":{"execution":{"iopub.status.busy":"2024-07-19T08:49:51.099782Z","iopub.execute_input":"2024-07-19T08:49:51.100185Z","iopub.status.idle":"2024-07-19T08:49:51.149907Z","shell.execute_reply.started":"2024-07-19T08:49:51.100153Z","shell.execute_reply":"2024-07-19T08:49:51.148911Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}