{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.11.11","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":31040,"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","trusted":true,"execution":{"iopub.status.busy":"2025-06-20T03:26:21.548741Z","iopub.execute_input":"2025-06-20T03:26:21.549103Z","iopub.status.idle":"2025-06-20T03:26:23.873252Z","shell.execute_reply.started":"2025-06-20T03:26:21.549027Z","shell.execute_reply":"2025-06-20T03:26:23.872230Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import matplotlib.pyplot as plt\n%matplotlib inline","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-20T03:26:23.875408Z","iopub.execute_input":"2025-06-20T03:26:23.875888Z","iopub.status.idle":"2025-06-20T03:26:23.881412Z","shell.execute_reply.started":"2025-06-20T03:26:23.875861Z","shell.execute_reply":"2025-06-20T03:26:23.880542Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df = pd.read_csv(\"../input/digit-recognizer/train.csv\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-20T03:26:23.882979Z","iopub.execute_input":"2025-06-20T03:26:23.883335Z","iopub.status.idle":"2025-06-20T03:26:28.015056Z","shell.execute_reply.started":"2025-06-20T03:26:23.883302Z","shell.execute_reply":"2025-06-20T03:26:28.014022Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-20T03:26:28.015996Z","iopub.execute_input":"2025-06-20T03:26:28.016239Z","iopub.status.idle":"2025-06-20T03:26:28.055599Z","shell.execute_reply.started":"2025-06-20T03:26:28.016219Z","shell.execute_reply":"2025-06-20T03:26:28.054434Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_arr = train_df.iloc[:, 1:].values.reshape((-1, 28, 28))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-20T03:26:28.058436Z","iopub.execute_input":"2025-06-20T03:26:28.058828Z","iopub.status.idle":"2025-06-20T03:26:28.075571Z","shell.execute_reply.started":"2025-06-20T03:26:28.058770Z","shell.execute_reply":"2025-06-20T03:26:28.074279Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_arr_2 = train_df.iloc[:, 1:].values","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-20T03:26:28.076575Z","iopub.execute_input":"2025-06-20T03:26:28.076898Z","iopub.status.idle":"2025-06-20T03:26:28.095179Z","shell.execute_reply.started":"2025-06-20T03:26:28.076865Z","shell.execute_reply":"2025-06-20T03:26:28.094125Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# train_arr[0]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-20T03:26:28.096221Z","iopub.execute_input":"2025-06-20T03:26:28.096494Z","iopub.status.idle":"2025-06-20T03:26:28.115653Z","shell.execute_reply.started":"2025-06-20T03:26:28.096471Z","shell.execute_reply":"2025-06-20T03:26:28.114625Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"plt.imshow(train_arr[0])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-20T03:26:28.116782Z","iopub.execute_input":"2025-06-20T03:26:28.117194Z","iopub.status.idle":"2025-06-20T03:26:28.414246Z","shell.execute_reply.started":"2025-06-20T03:26:28.117157Z","shell.execute_reply":"2025-06-20T03:26:28.413370Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"plt.imshow(train_arr[1])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-20T03:26:28.415238Z","iopub.execute_input":"2025-06-20T03:26:28.415574Z","iopub.status.idle":"2025-06-20T03:26:28.721225Z","shell.execute_reply.started":"2025-06-20T03:26:28.415537Z","shell.execute_reply":"2025-06-20T03:26:28.720266Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"def softmax(x):\n    return np.exp(x) / np.exp(x).sum(axis=0, keepdims=True)\n\ndef sigmoid(x):\n    return 1 / (1 + np.exp(-x))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-20T03:27:20.368117Z","iopub.execute_input":"2025-06-20T03:27:20.368414Z","iopub.status.idle":"2025-06-20T03:27:20.373696Z","shell.execute_reply.started":"2025-06-20T03:27:20.368391Z","shell.execute_reply":"2025-06-20T03:27:20.372697Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"x0 = (train_arr_2[0] / 256).reshape((-1, 1))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-20T03:27:20.679907Z","iopub.execute_input":"2025-06-20T03:27:20.680216Z","iopub.status.idle":"2025-06-20T03:27:20.685156Z","shell.execute_reply.started":"2025-06-20T03:27:20.680194Z","shell.execute_reply":"2025-06-20T03:27:20.684045Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"W1 = np.random.normal(size=(256, 784))\nb1 = np.random.normal(size=(256, 1))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-20T03:27:21.451369Z","iopub.execute_input":"2025-06-20T03:27:21.451818Z","iopub.status.idle":"2025-06-20T03:27:21.465727Z","shell.execute_reply.started":"2025-06-20T03:27:21.451772Z","shell.execute_reply":"2025-06-20T03:27:21.464712Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"x1 = sigmoid(np.matmul(W1, x0) + b1)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-20T03:27:54.953641Z","iopub.execute_input":"2025-06-20T03:27:54.954157Z","iopub.status.idle":"2025-06-20T03:27:54.959903Z","shell.execute_reply.started":"2025-06-20T03:27:54.954129Z","shell.execute_reply":"2025-06-20T03:27:54.958845Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"W2 = np.random.normal(size=(128, 256))\nb2 = np.random.normal(size=(128, 1))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-20T03:27:58.501285Z","iopub.execute_input":"2025-06-20T03:27:58.501610Z","iopub.status.idle":"2025-06-20T03:27:58.507864Z","shell.execute_reply.started":"2025-06-20T03:27:58.501581Z","shell.execute_reply":"2025-06-20T03:27:58.506893Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"x2 = sigmoid(np.matmul(W2, x1) + b2)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-20T03:28:00.081273Z","iopub.execute_input":"2025-06-20T03:28:00.081557Z","iopub.status.idle":"2025-06-20T03:28:00.086037Z","shell.execute_reply.started":"2025-06-20T03:28:00.081537Z","shell.execute_reply":"2025-06-20T03:28:00.084918Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"W3 = np.random.normal(size=(10, 128))\nb3 = np.random.normal(size=(10, 1))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-20T03:28:12.331385Z","iopub.execute_input":"2025-06-20T03:28:12.331688Z","iopub.status.idle":"2025-06-20T03:28:12.336647Z","shell.execute_reply.started":"2025-06-20T03:28:12.331667Z","shell.execute_reply":"2025-06-20T03:28:12.335829Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"x3 = softmax(np.matmul(W3, x2) + b3)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-20T03:28:20.713665Z","iopub.execute_input":"2025-06-20T03:28:20.713984Z","iopub.status.idle":"2025-06-20T03:28:20.719468Z","shell.execute_reply.started":"2025-06-20T03:28:20.713962Z","shell.execute_reply":"2025-06-20T03:28:20.718614Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"x3","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-20T03:28:23.122117Z","iopub.execute_input":"2025-06-20T03:28:23.122413Z","iopub.status.idle":"2025-06-20T03:28:23.129673Z","shell.execute_reply.started":"2025-06-20T03:28:23.122393Z","shell.execute_reply":"2025-06-20T03:28:23.128340Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}