{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.12.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"gpu","dataSources":[{"sourceId":3004,"databundleVersionId":861823,"sourceType":"competition"}],"dockerImageVersionId":31260,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"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","trusted":true},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# Digit Recognizer – Exploratory Data Analysis (EDA)\n\n## Competition: Digit Recognizer\n\n**Goal:**  \nAnalyze handwritten digit images and understand pixel patterns that help classify digits from 0 to 9.\n\n**Problem type:** Classification  \n**Data type:** Image (28x28 grayscale pixels, flattened)  \n**Target variable:** label (digit 0–9)  \n**Evaluation metric:** Accuracy  \n\nAccuracy measures the proportion of correctly classified digits out of all predictions.\n\nThis notebook focuses on Exploratory Data Analysis (EDA), including data structure inspection, visualization of digit samples, pixel intensity distributions, and class balance analysis to prepare for modeling.\n","metadata":{}},{"cell_type":"markdown","source":"## Imports","metadata":{}},{"cell_type":"code","source":"import pandas as pd\nimport matplotlib.pyplot as plt\nimport seaborn as sns","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-02-04T21:33:18.151027Z","iopub.execute_input":"2026-02-04T21:33:18.151898Z","iopub.status.idle":"2026-02-04T21:33:19.265474Z","shell.execute_reply.started":"2026-02-04T21:33:18.151840Z","shell.execute_reply":"2026-02-04T21:33:19.264927Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Load Data","metadata":{}},{"cell_type":"code","source":"df = pd.read_csv(\"/kaggle/input/digit-recognizer/train.csv\")\ndf.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-02-04T21:33:49.119126Z","iopub.execute_input":"2026-02-04T21:33:49.120080Z","iopub.status.idle":"2026-02-04T21:33:51.803303Z","shell.execute_reply.started":"2026-02-04T21:33:49.120037Z","shell.execute_reply":"2026-02-04T21:33:51.802510Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Dataset Overview\nWe start by inspecting the size and structure of the datasets.","metadata":{}},{"cell_type":"code","source":"df.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-02-04T21:35:08.739833Z","iopub.execute_input":"2026-02-04T21:35:08.740451Z","iopub.status.idle":"2026-02-04T21:35:08.745276Z","shell.execute_reply.started":"2026-02-04T21:35:08.740422Z","shell.execute_reply":"2026-02-04T21:35:08.744598Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df.info()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-02-04T21:35:16.248723Z","iopub.execute_input":"2026-02-04T21:35:16.249029Z","iopub.status.idle":"2026-02-04T21:35:16.276497Z","shell.execute_reply.started":"2026-02-04T21:35:16.249003Z","shell.execute_reply":"2026-02-04T21:35:16.275788Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df.describe()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-02-04T21:35:31.787496Z","iopub.execute_input":"2026-02-04T21:35:31.788028Z","iopub.status.idle":"2026-02-04T21:35:33.273179Z","shell.execute_reply.started":"2026-02-04T21:35:31.788001Z","shell.execute_reply":"2026-02-04T21:35:33.272474Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df.isnull().sum().sort_values(ascending=False)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-02-04T21:36:16.167004Z","iopub.execute_input":"2026-02-04T21:36:16.167390Z","iopub.status.idle":"2026-02-04T21:36:16.197678Z","shell.execute_reply.started":"2026-02-04T21:36:16.167363Z","shell.execute_reply":"2026-02-04T21:36:16.196963Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Target View\nDistribution of numbers (0-9)","metadata":{}},{"cell_type":"code","source":"sns.countplot(x=df[\"label\"])\nplt.title(\"Distribution of Digits\")\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-02-04T21:36:54.427053Z","iopub.execute_input":"2026-02-04T21:36:54.427607Z","iopub.status.idle":"2026-02-04T21:36:54.665628Z","shell.execute_reply.started":"2026-02-04T21:36:54.427581Z","shell.execute_reply":"2026-02-04T21:36:54.665063Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"The target classes (digits 0–9) are fairly balanced, which is good for classification using accuracy.","metadata":{}},{"cell_type":"markdown","source":"## Visualize images","metadata":{}},{"cell_type":"code","source":"image = df.drop(\"label\", axis=1).iloc[0].values.reshape(28,28)\nplt.imshow(image, cmap=\"gray\")\nplt.title(f\"Label: {df['label'].iloc[0]}\")\nplt.axis(\"off\")\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-02-04T21:39:10.387614Z","iopub.execute_input":"2026-02-04T21:39:10.388371Z","iopub.status.idle":"2026-02-04T21:39:10.520444Z","shell.execute_reply.started":"2026-02-04T21:39:10.388345Z","shell.execute_reply":"2026-02-04T21:39:10.519827Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"fig, axes = plt.subplots(1,5, figsize=(10,3))\n\nfor i, ax in enumerate(axes):\n    img = df.drop(\"label\", axis=1).iloc[i].values.reshape(28,28)\n    ax.imshow(img, cmap=\"gray\")\n    ax.set_title(df[\"label\"].iloc[i])\n    ax.axis(\"off\")\n\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-02-04T21:39:31.716378Z","iopub.execute_input":"2026-02-04T21:39:31.716638Z","iopub.status.idle":"2026-02-04T21:39:32.242191Z","shell.execute_reply.started":"2026-02-04T21:39:31.716618Z","shell.execute_reply":"2026-02-04T21:39:32.241487Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# Conclusion\n\nThe dataset consists of grayscale images of handwritten digits represented as pixel values.\nThe target variable is well balanced across classes.\nVisual inspection confirms clear digit patterns, making this dataset suitable for a classification task.","metadata":{}},{"cell_type":"markdown","source":"## Next Steps\n\nBased on the Exploratory Data Analysis, the following steps would be required for modeling:\n\n- Normalizing pixel values to improve model performance.\n- Splitting the dataset into training and validation sets.\n- Training a baseline classification model (e.g. Logistic Regression or simple Neural Network).\n- Evaluating model performance using Accuracy.\n- Analyzing misclassified digits to identify patterns and areas for improvement.\n\nThis notebook focuses on Exploratory Data Analysis only.","metadata":{}}]}