{"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\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":"2022-11-14T12:43:39.942944Z","iopub.execute_input":"2022-11-14T12:43:39.943322Z","iopub.status.idle":"2022-11-14T12:43:39.954787Z","shell.execute_reply.started":"2022-11-14T12:43:39.943292Z","shell.execute_reply":"2022-11-14T12:43:39.953735Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nimport seaborn as sns","metadata":{"execution":{"iopub.status.busy":"2022-11-14T12:43:39.956278Z","iopub.execute_input":"2022-11-14T12:43:39.956895Z","iopub.status.idle":"2022-11-14T12:43:39.962422Z","shell.execute_reply.started":"2022-11-14T12:43:39.956862Z","shell.execute_reply":"2022-11-14T12:43:39.961458Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.read_csv('/kaggle/input/digit-recognizer/train.csv')\nX = df.drop(columns=['label']).to_numpy()\ny = df['label'].to_numpy()\nX.shape , y.shape","metadata":{"execution":{"iopub.status.busy":"2022-11-14T12:43:39.966640Z","iopub.execute_input":"2022-11-14T12:43:39.967136Z","iopub.status.idle":"2022-11-14T12:43:42.464487Z","shell.execute_reply.started":"2022-11-14T12:43:39.967106Z","shell.execute_reply":"2022-11-14T12:43:42.463343Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X.min() , X.max()","metadata":{"execution":{"iopub.status.busy":"2022-11-14T12:43:42.466783Z","iopub.execute_input":"2022-11-14T12:43:42.467136Z","iopub.status.idle":"2022-11-14T12:43:42.539482Z","shell.execute_reply.started":"2022-11-14T12:43:42.467104Z","shell.execute_reply":"2022-11-14T12:43:42.538439Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(8,8))\nplt.imshow(X[36,:].reshape((28,28)),cmap='gray')\nplt.xticks([])\nplt.yticks([]);","metadata":{"execution":{"iopub.status.busy":"2022-11-14T12:43:42.541228Z","iopub.execute_input":"2022-11-14T12:43:42.541659Z","iopub.status.idle":"2022-11-14T12:43:42.665681Z","shell.execute_reply.started":"2022-11-14T12:43:42.541618Z","shell.execute_reply":"2022-11-14T12:43:42.664116Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import tensorflow as tf\nfrom tensorflow import keras\nfrom sklearn.preprocessing import MinMaxScaler\nfrom sklearn.model_selection import train_test_split","metadata":{"execution":{"iopub.status.busy":"2022-11-14T12:43:42.670045Z","iopub.execute_input":"2022-11-14T12:43:42.671046Z","iopub.status.idle":"2022-11-14T12:43:42.678234Z","shell.execute_reply.started":"2022-11-14T12:43:42.670983Z","shell.execute_reply":"2022-11-14T12:43:42.676759Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_scaled = MinMaxScaler().fit_transform(X)\nX_scaled.min(), X_scaled.max()","metadata":{"execution":{"iopub.status.busy":"2022-11-14T12:43:42.680492Z","iopub.execute_input":"2022-11-14T12:43:42.681410Z","iopub.status.idle":"2022-11-14T12:43:43.148679Z","shell.execute_reply.started":"2022-11-14T12:43:42.681353Z","shell.execute_reply":"2022-11-14T12:43:43.147547Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train, X_test, y_train, y_test = train_test_split(X_scaled,y,train_size=0.75,random_state=234)\nX_train.shape, X_test.shape, y_train.shape, y_test.shape","metadata":{"execution":{"iopub.status.busy":"2022-11-14T12:43:43.150013Z","iopub.execute_input":"2022-11-14T12:43:43.150341Z","iopub.status.idle":"2022-11-14T12:43:43.584684Z","shell.execute_reply.started":"2022-11-14T12:43:43.150303Z","shell.execute_reply":"2022-11-14T12:43:43.583522Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = keras.Sequential([\n    keras.layers.Dense(10, input_shape=(784,), activation='sigmoid')\n])\n\n\nmodel.compile(optimizer='adam',loss='sparse_categorical_crossentropy',metrics=['accuracy'])\n\n\nmodel.fit(X_train,y_train,epochs=5)","metadata":{"execution":{"iopub.status.busy":"2022-11-14T12:43:43.586361Z","iopub.execute_input":"2022-11-14T12:43:43.587315Z","iopub.status.idle":"2022-11-14T12:43:51.320594Z","shell.execute_reply.started":"2022-11-14T12:43:43.587278Z","shell.execute_reply":"2022-11-14T12:43:51.319816Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.evaluate(X_test,y_test)","metadata":{"execution":{"iopub.status.busy":"2022-11-14T12:43:51.321693Z","iopub.execute_input":"2022-11-14T12:43:51.322656Z","iopub.status.idle":"2022-11-14T12:43:51.877243Z","shell.execute_reply.started":"2022-11-14T12:43:51.322623Z","shell.execute_reply":"2022-11-14T12:43:51.876079Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model2 = keras.Sequential([\n    keras.layers.Dense(100, input_shape=(784,), activation='relu'),\n    keras.layers.Dense(100,activation='relu'),\n    keras.layers.Dense(10,activation='softmax')\n])\n\n\nmodel2.compile(optimizer='adam',loss='sparse_categorical_crossentropy',metrics=['accuracy'])\n\n\nmodel2.fit(X_train,y_train,epochs=5)","metadata":{"execution":{"iopub.status.busy":"2022-11-14T12:43:51.878463Z","iopub.execute_input":"2022-11-14T12:43:51.878815Z","iopub.status.idle":"2022-11-14T12:44:03.781281Z","shell.execute_reply.started":"2022-11-14T12:43:51.878777Z","shell.execute_reply":"2022-11-14T12:44:03.780454Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model2.evaluate(X_test,y_test)","metadata":{"execution":{"iopub.status.busy":"2022-11-14T12:44:03.785023Z","iopub.execute_input":"2022-11-14T12:44:03.785571Z","iopub.status.idle":"2022-11-14T12:44:04.487023Z","shell.execute_reply.started":"2022-11-14T12:44:03.785528Z","shell.execute_reply":"2022-11-14T12:44:04.485768Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_predict = [np.argmax(i) for i in model2.predict(X_test)]","metadata":{"execution":{"iopub.status.busy":"2022-11-14T12:44:04.488642Z","iopub.execute_input":"2022-11-14T12:44:04.489060Z","iopub.status.idle":"2022-11-14T12:44:04.981176Z","shell.execute_reply.started":"2022-11-14T12:44:04.489028Z","shell.execute_reply":"2022-11-14T12:44:04.980045Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"confusion_matrix = tf.math.confusion_matrix(labels=y_test,predictions=y_predict)","metadata":{"execution":{"iopub.status.busy":"2022-11-14T12:44:04.982695Z","iopub.execute_input":"2022-11-14T12:44:04.983158Z","iopub.status.idle":"2022-11-14T12:44:04.999612Z","shell.execute_reply.started":"2022-11-14T12:44:04.983120Z","shell.execute_reply":"2022-11-14T12:44:04.998712Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(10,8))\nsns.heatmap(confusion_matrix,annot=True)\nplt.xlabel('Predicted')\nplt.ylabel('Truth');\n","metadata":{"execution":{"iopub.status.busy":"2022-11-14T12:44:05.001193Z","iopub.execute_input":"2022-11-14T12:44:05.001737Z","iopub.status.idle":"2022-11-14T12:44:05.708566Z","shell.execute_reply.started":"2022-11-14T12:44:05.001685Z","shell.execute_reply":"2022-11-14T12:44:05.707719Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df2 = pd.read_csv('/kaggle/input/chinese-mnist-digit-recognizer/chineseMNIST.csv')\ndf2","metadata":{"execution":{"iopub.status.busy":"2022-11-14T13:04:29.762527Z","iopub.execute_input":"2022-11-14T13:04:29.763443Z","iopub.status.idle":"2022-11-14T13:04:38.194387Z","shell.execute_reply.started":"2022-11-14T13:04:29.763393Z","shell.execute_reply":"2022-11-14T13:04:38.193087Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X2 = df2.drop(columns=['label','character']).to_numpy()\ny2 = df2['label'].to_numpy()\ncharacters = df2['character']\nX2.shape, y2.shape","metadata":{"execution":{"iopub.status.busy":"2022-11-14T13:04:41.442528Z","iopub.execute_input":"2022-11-14T13:04:41.443000Z","iopub.status.idle":"2022-11-14T13:04:41.775987Z","shell.execute_reply.started":"2022-11-14T13:04:41.442964Z","shell.execute_reply":"2022-11-14T13:04:41.774798Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"np.unique(y2)","metadata":{"execution":{"iopub.status.busy":"2022-11-14T13:04:43.464952Z","iopub.execute_input":"2022-11-14T13:04:43.465428Z","iopub.status.idle":"2022-11-14T13:04:43.472544Z","shell.execute_reply.started":"2022-11-14T13:04:43.465389Z","shell.execute_reply":"2022-11-14T13:04:43.471172Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y2[y2 == 100] = 11\ny2[y2 == 1000] = 12\ny2[y2 == 10000] = 13\ny2[y2 == 100000000] = 14","metadata":{"execution":{"iopub.status.busy":"2022-11-14T13:07:18.953747Z","iopub.execute_input":"2022-11-14T13:07:18.954221Z","iopub.status.idle":"2022-11-14T13:07:18.961325Z","shell.execute_reply.started":"2022-11-14T13:07:18.954189Z","shell.execute_reply":"2022-11-14T13:07:18.959997Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(8,8))\nplt.imshow(X2[24,:].reshape((64,64)),cmap='gray')\nplt.xticks([])\nplt.yticks([]);","metadata":{"execution":{"iopub.status.busy":"2022-11-14T13:04:49.349095Z","iopub.execute_input":"2022-11-14T13:04:49.350162Z","iopub.status.idle":"2022-11-14T13:04:49.476657Z","shell.execute_reply.started":"2022-11-14T13:04:49.350115Z","shell.execute_reply":"2022-11-14T13:04:49.474978Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X2_scaled = MinMaxScaler().fit_transform(X2)","metadata":{"execution":{"iopub.status.busy":"2022-11-14T13:07:41.024772Z","iopub.execute_input":"2022-11-14T13:07:41.025674Z","iopub.status.idle":"2022-11-14T13:07:41.921042Z","shell.execute_reply.started":"2022-11-14T13:07:41.025631Z","shell.execute_reply":"2022-11-14T13:07:41.920149Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X2_train, X2_test, y2_train, y2_test = train_test_split(X2_scaled,y2,train_size=0.75,random_state=234)\nX2_train.shape, X2_test.shape, y2_train.shape, y2_test.shape","metadata":{"execution":{"iopub.status.busy":"2022-11-14T13:07:44.970201Z","iopub.execute_input":"2022-11-14T13:07:44.970695Z","iopub.status.idle":"2022-11-14T13:07:46.047716Z","shell.execute_reply.started":"2022-11-14T13:07:44.970655Z","shell.execute_reply":"2022-11-14T13:07:46.046263Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model3 = keras.Sequential([\n    keras.layers.Dense(15,input_shape=(4096,),activation='sigmoid')\n])\n\nmodel3.compile(optimizer='adam',loss='sparse_categorical_crossentropy',metrics=['accuracy'])\n\nmodel3.fit(X2_train,y2_train,epochs=5)","metadata":{"execution":{"iopub.status.busy":"2022-11-14T13:07:47.872849Z","iopub.execute_input":"2022-11-14T13:07:47.873530Z","iopub.status.idle":"2022-11-14T13:07:52.470339Z","shell.execute_reply.started":"2022-11-14T13:07:47.873494Z","shell.execute_reply":"2022-11-14T13:07:52.468844Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model3.evaluate(X2_test,y2_test)","metadata":{"execution":{"iopub.status.busy":"2022-11-14T13:09:02.191482Z","iopub.execute_input":"2022-11-14T13:09:02.192942Z","iopub.status.idle":"2022-11-14T13:09:02.573599Z","shell.execute_reply.started":"2022-11-14T13:09:02.192871Z","shell.execute_reply":"2022-11-14T13:09:02.572666Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model4 = keras.Sequential([\n    keras.layers.Dense(100,input_shape=(4096,),activation='relu'),\n    keras.layers.Dense(80,activation='relu'),\n    keras.layers.Dense(65,activation='relu'),\n    keras.layers.Dense(15,activation='softmax')\n])\n\nmodel4.compile(optimizer='adam',loss='sparse_categorical_crossentropy',metrics=['accuracy'])\n\nmodel4.fit(X2_train,y2_train,epochs=15)","metadata":{"execution":{"iopub.status.busy":"2022-11-14T13:21:58.756512Z","iopub.execute_input":"2022-11-14T13:21:58.756957Z","iopub.status.idle":"2022-11-14T13:22:30.632708Z","shell.execute_reply.started":"2022-11-14T13:21:58.756925Z","shell.execute_reply":"2022-11-14T13:22:30.631357Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model4.evaluate(X2_test,y2_test)","metadata":{"execution":{"iopub.status.busy":"2022-11-14T13:22:38.098058Z","iopub.execute_input":"2022-11-14T13:22:38.098488Z","iopub.status.idle":"2022-11-14T13:22:38.742408Z","shell.execute_reply.started":"2022-11-14T13:22:38.098458Z","shell.execute_reply":"2022-11-14T13:22:38.741361Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y2_predict = [np.argmax(i) for i in model4.predict(X2_test)]","metadata":{"execution":{"iopub.status.busy":"2022-11-14T13:23:26.318530Z","iopub.execute_input":"2022-11-14T13:23:26.319496Z","iopub.status.idle":"2022-11-14T13:23:26.790776Z","shell.execute_reply.started":"2022-11-14T13:23:26.319450Z","shell.execute_reply":"2022-11-14T13:23:26.789583Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"confusion_matrix2 = tf.math.confusion_matrix(labels=y2_test,predictions=y2_predict)\nplt.figure(figsize=(10,8))\nsns.heatmap(confusion_matrix2,annot=True)\nplt.xlabel('Predicted')\nplt.ylabel('Truth');","metadata":{"execution":{"iopub.status.busy":"2022-11-14T13:25:09.021997Z","iopub.execute_input":"2022-11-14T13:25:09.022404Z","iopub.status.idle":"2022-11-14T13:25:10.214956Z","shell.execute_reply.started":"2022-11-14T13:25:09.022373Z","shell.execute_reply":"2022-11-14T13:25:10.213682Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df3 = pd.read_csv('/kaggle/input/fashionmnist/fashion-mnist_train.csv')\ndf3","metadata":{"execution":{"iopub.status.busy":"2022-11-14T13:26:47.073204Z","iopub.execute_input":"2022-11-14T13:26:47.073592Z","iopub.status.idle":"2022-11-14T13:26:52.755117Z","shell.execute_reply.started":"2022-11-14T13:26:47.073561Z","shell.execute_reply":"2022-11-14T13:26:52.754287Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X3 = df3.drop(columns=['label']).to_numpy()\ny3 = df3['label'].to_numpy()\nX3.shape , y3.shape","metadata":{"execution":{"iopub.status.busy":"2022-11-14T13:27:46.150852Z","iopub.execute_input":"2022-11-14T13:27:46.151263Z","iopub.status.idle":"2022-11-14T13:27:46.328421Z","shell.execute_reply.started":"2022-11-14T13:27:46.151233Z","shell.execute_reply":"2022-11-14T13:27:46.327345Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(8,8))\nplt.imshow(X3[39,:].reshape((28,28)),cmap='gray')\nplt.xticks([])\nplt.yticks([]);","metadata":{"execution":{"iopub.status.busy":"2022-11-14T13:28:43.177181Z","iopub.execute_input":"2022-11-14T13:28:43.177794Z","iopub.status.idle":"2022-11-14T13:28:43.297141Z","shell.execute_reply.started":"2022-11-14T13:28:43.177742Z","shell.execute_reply":"2022-11-14T13:28:43.295604Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X3_scaled = MinMaxScaler().fit_transform(X3)\nX3_scaled.min(), X3_scaled.max()","metadata":{"execution":{"iopub.status.busy":"2022-11-14T13:30:04.398832Z","iopub.execute_input":"2022-11-14T13:30:04.399237Z","iopub.status.idle":"2022-11-14T13:30:05.033140Z","shell.execute_reply.started":"2022-11-14T13:30:04.399207Z","shell.execute_reply":"2022-11-14T13:30:05.031934Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X3_train, X3_test, y3_train, y3_test = train_test_split(X3_scaled,y3,train_size=0.75,random_state=234)\nX_train.shape, X_test.shape, y_train.shape, y_test.shape","metadata":{"execution":{"iopub.status.busy":"2022-11-14T13:30:14.814315Z","iopub.execute_input":"2022-11-14T13:30:14.815279Z","iopub.status.idle":"2022-11-14T13:30:15.443390Z","shell.execute_reply.started":"2022-11-14T13:30:14.815243Z","shell.execute_reply":"2022-11-14T13:30:15.442206Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"np.unique(y3)","metadata":{"execution":{"iopub.status.busy":"2022-11-14T13:31:12.319618Z","iopub.execute_input":"2022-11-14T13:31:12.320056Z","iopub.status.idle":"2022-11-14T13:31:12.328047Z","shell.execute_reply.started":"2022-11-14T13:31:12.320023Z","shell.execute_reply":"2022-11-14T13:31:12.327154Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.fit(X3_train,y3_train,epochs=5)","metadata":{"execution":{"iopub.status.busy":"2022-11-14T13:33:39.783732Z","iopub.execute_input":"2022-11-14T13:33:39.784179Z","iopub.status.idle":"2022-11-14T13:33:51.422340Z","shell.execute_reply.started":"2022-11-14T13:33:39.784146Z","shell.execute_reply":"2022-11-14T13:33:51.421369Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.evaluate(X3_test,y3_test)","metadata":{"execution":{"iopub.status.busy":"2022-11-14T13:34:19.308222Z","iopub.execute_input":"2022-11-14T13:34:19.309200Z","iopub.status.idle":"2022-11-14T13:34:20.014091Z","shell.execute_reply.started":"2022-11-14T13:34:19.309164Z","shell.execute_reply":"2022-11-14T13:34:20.013105Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model2.fit(X3_train,y3_train,epochs=10)","metadata":{"execution":{"iopub.status.busy":"2022-11-14T13:35:37.138334Z","iopub.execute_input":"2022-11-14T13:35:37.138727Z","iopub.status.idle":"2022-11-14T13:36:12.403709Z","shell.execute_reply.started":"2022-11-14T13:35:37.138695Z","shell.execute_reply":"2022-11-14T13:36:12.402836Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model2.evaluate(X3_test,y3_test)","metadata":{"execution":{"iopub.status.busy":"2022-11-14T13:36:26.577932Z","iopub.execute_input":"2022-11-14T13:36:26.578921Z","iopub.status.idle":"2022-11-14T13:36:27.390373Z","shell.execute_reply.started":"2022-11-14T13:36:26.578883Z","shell.execute_reply":"2022-11-14T13:36:27.389478Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y3_predict = [np.argmax(i) for i in model2.predict(X3_test)]\nconfusion_matrix3 = tf.math.confusion_matrix(labels=y3_test,predictions=y3_predict)\nplt.figure(figsize=(10,8))\nsns.heatmap(confusion_matrix3,annot=True)\nplt.xlabel('Predicted')\nplt.ylabel('Truth');","metadata":{"execution":{"iopub.status.busy":"2022-11-14T13:38:13.363834Z","iopub.execute_input":"2022-11-14T13:38:13.364219Z","iopub.status.idle":"2022-11-14T13:38:14.739842Z","shell.execute_reply.started":"2022-11-14T13:38:13.364188Z","shell.execute_reply":"2022-11-14T13:38:14.738665Z"},"trusted":true},"execution_count":null,"outputs":[]}]}