{"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\n# import numpy as np # linear algebra\n# import 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\n# import os\n# for 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_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np \nimport pandas as pd \nimport matplotlib.pyplot as plt \nimport seaborn as sns \nimport cv2\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.metrics import confusion_matrix\nfrom keras.utils.np_utils import to_categorical\nimport tensorflow as tf\nfrom tensorflow.keras import Sequential\nfrom tensorflow.keras.layers import Dropout,Dense,Flatten,LeakyReLU,BatchNormalization\nimport warnings\nwarnings.filterwarnings('ignore')","metadata":{"execution":{"iopub.status.busy":"2022-11-09T10:13:16.396946Z","iopub.execute_input":"2022-11-09T10:13:16.397400Z","iopub.status.idle":"2022-11-09T10:13:16.405374Z","shell.execute_reply.started":"2022-11-09T10:13:16.397364Z","shell.execute_reply":"2022-11-09T10:13:16.403767Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df=pd.read_csv('../input/Kannada-MNIST/train.csv')\nprint(df)\ndf.describe()\n","metadata":{"execution":{"iopub.status.busy":"2022-11-09T09:46:58.676429Z","iopub.execute_input":"2022-11-09T09:46:58.677226Z","iopub.status.idle":"2022-11-09T09:47:06.619678Z","shell.execute_reply.started":"2022-11-09T09:46:58.677188Z","shell.execute_reply":"2022-11-09T09:47:06.618254Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"raw_train=pd.read_csv('../input/Kannada-MNIST/train.csv')\nx=raw_train.iloc[:,1:]/255\ny=raw_train.iloc[:,0]\n","metadata":{"execution":{"iopub.status.busy":"2022-11-09T10:27:16.160038Z","iopub.execute_input":"2022-11-09T10:27:16.160447Z","iopub.status.idle":"2022-11-09T10:27:19.927521Z","shell.execute_reply.started":"2022-11-09T10:27:16.160416Z","shell.execute_reply":"2022-11-09T10:27:19.926334Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x.shape","metadata":{"execution":{"iopub.status.busy":"2022-11-09T10:27:19.929082Z","iopub.execute_input":"2022-11-09T10:27:19.929447Z","iopub.status.idle":"2022-11-09T10:27:19.938394Z","shell.execute_reply.started":"2022-11-09T10:27:19.929416Z","shell.execute_reply":"2022-11-09T10:27:19.936991Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_train,x_val,y_train,y_val=train_test_split(x,y,test_size=0.3,random_state=42)","metadata":{"execution":{"iopub.status.busy":"2022-11-09T10:27:24.263897Z","iopub.execute_input":"2022-11-09T10:27:24.264602Z","iopub.status.idle":"2022-11-09T10:27:24.697888Z","shell.execute_reply.started":"2022-11-09T10:27:24.264563Z","shell.execute_reply":"2022-11-09T10:27:24.696858Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_train.shape","metadata":{"execution":{"iopub.status.busy":"2022-11-09T10:27:30.309356Z","iopub.execute_input":"2022-11-09T10:27:30.309913Z","iopub.status.idle":"2022-11-09T10:27:30.318452Z","shell.execute_reply.started":"2022-11-09T10:27:30.309872Z","shell.execute_reply":"2022-11-09T10:27:30.317017Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# x_train=x_train.values.reshape(-1,28,28,1)\n# x_val=x_val.values.reshape(-1,28,28,1)\n# y_train=to_categorical(y_train)#the labels will be in the same fromat as the reshaped x_train \n# y_val=to_categorical(y_val)","metadata":{"execution":{"iopub.status.busy":"2022-11-09T09:49:13.175601Z","iopub.execute_input":"2022-11-09T09:49:13.176045Z","iopub.status.idle":"2022-11-09T09:49:13.184967Z","shell.execute_reply.started":"2022-11-09T09:49:13.176013Z","shell.execute_reply":"2022-11-09T09:49:13.183473Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model=tf.keras.models.Sequential([\n    tf.keras.layers.Dense(400,activation=\"relu\",input_shape=(42000, 784)),\n    tf.keras.layers.Dense(300,activation=\"relu\"),\n    tf.keras.layers.Dense(100,activation=\"relu\"),\n    tf.keras.layers.Dense(100,activation=\"relu\"),\n#     tf.keras.layers.BatchNormalisation(momentum=0.15),\n    tf.keras.layers.Dropout(0.25),\n    tf.keras.layers.Dense(10,activation=\"softmax\")\n])","metadata":{"execution":{"iopub.status.busy":"2022-11-09T10:28:25.171495Z","iopub.execute_input":"2022-11-09T10:28:25.172099Z","iopub.status.idle":"2022-11-09T10:28:25.362589Z","shell.execute_reply.started":"2022-11-09T10:28:25.172054Z","shell.execute_reply":"2022-11-09T10:28:25.361007Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.summary()","metadata":{"execution":{"iopub.status.busy":"2022-11-09T10:28:29.278991Z","iopub.execute_input":"2022-11-09T10:28:29.279518Z","iopub.status.idle":"2022-11-09T10:28:29.288386Z","shell.execute_reply.started":"2022-11-09T10:28:29.279479Z","shell.execute_reply":"2022-11-09T10:28:29.286754Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.compile(loss=\"sparse_categorical_crossentropy\",\n              optimizer=\"sgd\",\n              metrics=[\"accuracy\"])","metadata":{"execution":{"iopub.status.busy":"2022-11-09T10:39:41.263740Z","iopub.execute_input":"2022-11-09T10:39:41.265051Z","iopub.status.idle":"2022-11-09T10:39:41.286116Z","shell.execute_reply.started":"2022-11-09T10:39:41.264992Z","shell.execute_reply":"2022-11-09T10:39:41.284507Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"history = model.fit(x_train, y_train, epochs=5,\n                    validation_data=(x_val, y_val))","metadata":{"execution":{"iopub.status.busy":"2022-11-09T10:40:19.614512Z","iopub.execute_input":"2022-11-09T10:40:19.615405Z","iopub.status.idle":"2022-11-09T10:41:01.725391Z","shell.execute_reply.started":"2022-11-09T10:40:19.615359Z","shell.execute_reply":"2022-11-09T10:41:01.723814Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test=pd.read_csv('../input/Kannada-MNIST/test.csv')\ntest1=test.iloc[2:3,1:]\n# print(test1)","metadata":{"execution":{"iopub.status.busy":"2022-11-09T10:52:30.756874Z","iopub.execute_input":"2022-11-09T10:52:30.758070Z","iopub.status.idle":"2022-11-09T10:52:31.060438Z","shell.execute_reply.started":"2022-11-09T10:52:30.758028Z","shell.execute_reply":"2022-11-09T10:52:31.059489Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\ntest=test.drop(['id'],axis=1)/255","metadata":{"execution":{"iopub.status.busy":"2022-11-09T10:52:32.898186Z","iopub.execute_input":"2022-11-09T10:52:32.898745Z","iopub.status.idle":"2022-11-09T10:52:32.938871Z","shell.execute_reply.started":"2022-11-09T10:52:32.898702Z","shell.execute_reply":"2022-11-09T10:52:32.937430Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test.shape","metadata":{"execution":{"iopub.status.busy":"2022-11-09T10:52:38.603588Z","iopub.execute_input":"2022-11-09T10:52:38.604102Z","iopub.status.idle":"2022-11-09T10:52:38.614186Z","shell.execute_reply.started":"2022-11-09T10:52:38.604063Z","shell.execute_reply":"2022-11-09T10:52:38.612953Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Yp=model.predict(test)\nYp=np.argmax(Yp,axis=1)\nprint(Yp)","metadata":{"execution":{"iopub.status.busy":"2022-11-09T11:27:29.992767Z","iopub.execute_input":"2022-11-09T11:27:29.993301Z","iopub.status.idle":"2022-11-09T11:27:30.441771Z","shell.execute_reply.started":"2022-11-09T11:27:29.993261Z","shell.execute_reply":"2022-11-09T11:27:30.440274Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample_sub=pd.read_csv('../input/Kannada-MNIST/sample_submission.csv')\nsample_sub['label']=Yp\nsample_sub.to_csv('submission.csv',index=False)","metadata":{"execution":{"iopub.status.busy":"2022-11-09T11:27:33.540739Z","iopub.execute_input":"2022-11-09T11:27:33.541805Z","iopub.status.idle":"2022-11-09T11:27:33.566668Z","shell.execute_reply.started":"2022-11-09T11:27:33.541750Z","shell.execute_reply":"2022-11-09T11:27:33.565342Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample_sub","metadata":{"execution":{"iopub.status.busy":"2022-11-09T10:55:10.051199Z","iopub.execute_input":"2022-11-09T10:55:10.052293Z","iopub.status.idle":"2022-11-09T10:55:10.064433Z","shell.execute_reply.started":"2022-11-09T10:55:10.052254Z","shell.execute_reply":"2022-11-09T10:55:10.063165Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_val.shape\n","metadata":{"execution":{"iopub.status.busy":"2022-11-09T11:27:38.478565Z","iopub.execute_input":"2022-11-09T11:27:38.479094Z","iopub.status.idle":"2022-11-09T11:27:38.487484Z","shell.execute_reply.started":"2022-11-09T11:27:38.479054Z","shell.execute_reply":"2022-11-09T11:27:38.486451Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Yp2=model.predict(x_val)\nYp2=np.argmax(Yp2,axis=1)\nYp1=y_val.astype(int)\n# print(test0)\nCmtx=confusion_matrix(Yp1,Yp2)\nCmtx=pd.DataFrame(Cmtx,index=range(0,10),columns=range(0,10))\nCmtx","metadata":{"execution":{"iopub.status.busy":"2022-11-09T11:29:37.828126Z","iopub.execute_input":"2022-11-09T11:29:37.828585Z","iopub.status.idle":"2022-11-09T11:29:39.008774Z","shell.execute_reply.started":"2022-11-09T11:29:37.828549Z","shell.execute_reply":"2022-11-09T11:29:39.007526Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}