{"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":16017,"databundleVersionId":708189,"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":"2025-06-15T11:51:40.698212Z","iopub.execute_input":"2025-06-15T11:51:40.699418Z","iopub.status.idle":"2025-06-15T11:51:41.198669Z","shell.execute_reply.started":"2025-06-15T11:51:40.699352Z","shell.execute_reply":"2025-06-15T11:51:41.197654Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# Basic Deeplearning explained for MINIST\n#### Goal:- To show you how easy it could be to make your first deep leaning model","metadata":{}},{"cell_type":"code","source":"import pandas as pd\nimport tensorflow as tf\nfrom tensorflow import keras\nimport matplotlib.pyplot as plt\n%matplotlib inline\nimport numpy as np\nfrom sklearn.model_selection import train_test_split","metadata":{"execution":{"iopub.status.busy":"2025-06-15T11:51:41.200389Z","iopub.execute_input":"2025-06-15T11:51:41.200829Z","iopub.status.idle":"2025-06-15T11:51:58.188805Z","shell.execute_reply.started":"2025-06-15T11:51:41.200783Z","shell.execute_reply":"2025-06-15T11:51:58.187829Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Loading of data","metadata":{}},{"cell_type":"code","source":"x = pd.read_csv(\"/kaggle/input/Kannada-MNIST/train.csv\")\ny = pd.read_csv(\"/kaggle/input/Kannada-MNIST/test.csv\")","metadata":{"execution":{"iopub.status.busy":"2025-06-15T11:51:58.190338Z","iopub.execute_input":"2025-06-15T11:51:58.190905Z","iopub.status.idle":"2025-06-15T11:52:04.272087Z","shell.execute_reply.started":"2025-06-15T11:51:58.190865Z","shell.execute_reply":"2025-06-15T11:52:04.271233Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Cleaning and spliting\n#### We all know the MNIST dataset is widely recognized for its cleanliness and consistency, making it an ideal benchmark for learners and practitioners.\n#### Here we will focus more on building and Evaluating model.\n","metadata":{}},{"cell_type":"code","source":"x_train, x_test, y_train, y_test = train_test_split(\n    x.drop(columns=[\"label\"]), x[\"label\"])","metadata":{"execution":{"iopub.status.busy":"2025-06-15T11:52:04.273584Z","iopub.execute_input":"2025-06-15T11:52:04.273877Z","iopub.status.idle":"2025-06-15T11:52:04.792285Z","shell.execute_reply.started":"2025-06-15T11:52:04.273853Z","shell.execute_reply":"2025-06-15T11:52:04.791170Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Training and Fitting the model","metadata":{}},{"cell_type":"code","source":"# Making a simple model with \n## 1st layer -          with 500 input nodes (input_shape=(784,) -- MNIST images are 28×28, flattened to a 784-length vector. )\n## Dropout -            0.2 = 20% of the neurons (Prevents overfitting)\n## 2nd hidden layer -   200 input nodes (\"relu\" is an activation function helps in normalizing the neuron output and give forward)\n## 3rd Output layer -   10 output nodes (becase it has 10 numbers to predict {0-9})\n\nmodel = keras.Sequential([\n    keras.layers.Dense(500, input_shape=(784,), activation='relu'),\n    keras.layers.Dropout(0.2),\n    keras.layers.Dense(200, activation='relu'),\n    keras.layers.Dense(10, activation='sigmoid')\n])\n\nmodel.compile(optimizer='adam',  # adjusts learning rates automatically.\n              loss='sparse_categorical_crossentropy',\n              metrics=['accuracy']) # Tracks the accuracy of predictions\n","metadata":{"execution":{"iopub.status.busy":"2025-06-15T11:52:04.794365Z","iopub.execute_input":"2025-06-15T11:52:04.794701Z","iopub.status.idle":"2025-06-15T11:52:04.926050Z","shell.execute_reply.started":"2025-06-15T11:52:04.794675Z","shell.execute_reply":"2025-06-15T11:52:04.924994Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"model.fit(x_train, y_train, epochs=10)","metadata":{"execution":{"iopub.status.busy":"2025-06-15T11:52:04.927166Z","iopub.execute_input":"2025-06-15T11:52:04.927462Z","iopub.status.idle":"2025-06-15T11:53:27.907708Z","shell.execute_reply.started":"2025-06-15T11:52:04.927437Z","shell.execute_reply":"2025-06-15T11:53:27.906686Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Evaluation and results","metadata":{}},{"cell_type":"code","source":"model.evaluate(x_test, y_test)\ny_predicted = model.predict(x_test)\n# y_predicted","metadata":{"execution":{"iopub.status.busy":"2025-06-15T11:53:27.908998Z","iopub.execute_input":"2025-06-15T11:53:27.909373Z","iopub.status.idle":"2025-06-15T11:53:30.599611Z","shell.execute_reply.started":"2025-06-15T11:53:27.909347Z","shell.execute_reply":"2025-06-15T11:53:30.598651Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(np.argmax(y_predicted[0]))\nprint(y_test.iloc[0])","metadata":{"execution":{"iopub.status.busy":"2025-06-15T11:53:30.601236Z","iopub.execute_input":"2025-06-15T11:53:30.601665Z","iopub.status.idle":"2025-06-15T11:53:30.611293Z","shell.execute_reply.started":"2025-06-15T11:53:30.601630Z","shell.execute_reply":"2025-06-15T11:53:30.610273Z"},"trusted":true},"outputs":[],"execution_count":null}]}