{"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":"markdown","source":"### Importing Basic Pacakges / ಕೆಲವೊಂದು ಅಡಿಯ ಕಟ್ಟುಗಳನ್ನು ಒಳತರಲಾಗುವುದು","metadata":{}},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nfrom sklearn.metrics import confusion_matrix,accuracy_score\n%matplotlib inline","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-06-15T05:22:51.523094Z","iopub.execute_input":"2022-06-15T05:22:51.523859Z","iopub.status.idle":"2022-06-15T05:22:52.651368Z","shell.execute_reply.started":"2022-06-15T05:22:51.523756Z","shell.execute_reply":"2022-06-15T05:22:52.650663Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Extracting the data / ತಿಳಿಹವನ್ನು ಹೊರತೆಗೆಯುವುವಿಕೆ\n","metadata":{}},{"cell_type":"code","source":"train = pd.read_csv('../input/Kannada-MNIST/train.csv')\ntest = pd.read_csv('../input/Kannada-MNIST/test.csv')\ndig_mnist = pd.read_csv('../input/Kannada-MNIST/Dig-MNIST.csv')","metadata":{"execution":{"iopub.status.busy":"2022-06-15T05:22:52.653067Z","iopub.execute_input":"2022-06-15T05:22:52.653394Z","iopub.status.idle":"2022-06-15T05:22:58.548005Z","shell.execute_reply.started":"2022-06-15T05:22:52.653354Z","shell.execute_reply":"2022-06-15T05:22:58.547116Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.head()","metadata":{"execution":{"iopub.status.busy":"2022-06-15T05:22:58.549787Z","iopub.execute_input":"2022-06-15T05:22:58.550348Z","iopub.status.idle":"2022-06-15T05:22:58.58518Z","shell.execute_reply.started":"2022-06-15T05:22:58.550308Z","shell.execute_reply":"2022-06-15T05:22:58.584136Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.info()","metadata":{"execution":{"iopub.status.busy":"2022-06-15T05:22:58.59133Z","iopub.execute_input":"2022-06-15T05:22:58.593527Z","iopub.status.idle":"2022-06-15T05:22:58.67343Z","shell.execute_reply.started":"2022-06-15T05:22:58.593448Z","shell.execute_reply":"2022-06-15T05:22:58.672682Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(train.shape)\nprint(test.shape)","metadata":{"execution":{"iopub.status.busy":"2022-06-15T05:22:58.676748Z","iopub.execute_input":"2022-06-15T05:22:58.679953Z","iopub.status.idle":"2022-06-15T05:22:58.685885Z","shell.execute_reply.started":"2022-06-15T05:22:58.679898Z","shell.execute_reply":"2022-06-15T05:22:58.685Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Checking whether data is balanced or not.\n# ಗುರುತಿನ ತಿಳಿಹುವನ್ನು ಸರಿತೂಕ ಮಾಡಿ.\nvalues = train['label'].value_counts()\nsns.barplot(values.index,values)","metadata":{"execution":{"iopub.status.busy":"2022-06-15T05:22:58.688514Z","iopub.execute_input":"2022-06-15T05:22:58.690447Z","iopub.status.idle":"2022-06-15T05:22:59.058198Z","shell.execute_reply.started":"2022-06-15T05:22:58.690402Z","shell.execute_reply":"2022-06-15T05:22:59.057402Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":" **Target Classes are fairly distributed. We have 6000 samples for each numbers in kannada for training.**","metadata":{}},{"cell_type":"code","source":"# Checking the rows by specifying the row number.\nfeatures = [\"pixel{}\".format(pixel_num) for pixel_num in range (0,784)]# Stores the pixel array from pixel1 to pixel785\nrows_to_examine = 9\nimage_data = np.reshape(train[features][rows_to_examine:rows_to_examine + 1].to_numpy(),(28,28))\nplt.imshow(image_data,cmap='gray')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-06-15T05:22:59.059414Z","iopub.execute_input":"2022-06-15T05:22:59.059707Z","iopub.status.idle":"2022-06-15T05:22:59.357092Z","shell.execute_reply.started":"2022-06-15T05:22:59.059671Z","shell.execute_reply":"2022-06-15T05:22:59.356337Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Data Preparation / ತಿಳಿಹುವಿನ ಸಮೆಯುವಿಕೆ","metadata":{}},{"cell_type":"markdown","source":"#### Spliting train datasets for x and y variables / ಪಳಗಿಸುವ ತಿಳಿಹುಗಳಿಂದ ಗುರುತು(y) ಮತ್ತು ತಾನ್ಮೆ(x) ಮಾರ್ಪುಕಗಳಿಗೆ ಬೇರೆ ಮಾಡುವುದು\n","metadata":{}},{"cell_type":"code","source":"x = train.drop('label',axis = 1)\ny = train['label']\nprint(x.shape)\nprint(y.shape)","metadata":{"execution":{"iopub.status.busy":"2022-06-15T05:22:59.358865Z","iopub.execute_input":"2022-06-15T05:22:59.359071Z","iopub.status.idle":"2022-06-15T05:22:59.527526Z","shell.execute_reply.started":"2022-06-15T05:22:59.359045Z","shell.execute_reply":"2022-06-15T05:22:59.525964Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### Splitting Datasets into Train and Test / ತಿಳಿಹುವನ್ನು ಪಳಗಿಸುವ ಮತ್ತು ಒರೆತಗಳಿಗೆ ಬೇರ್ಪಡಿಸುವಿಕೆ.","metadata":{}},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\nx_train,x_test,y_train,y_test = train_test_split(x,y,test_size=0.25,random_state=46)\nprint(x_train.shape)\nprint(y_train.shape)\nprint(x_test.shape)\nprint(y_test.shape)","metadata":{"execution":{"iopub.status.busy":"2022-06-15T05:22:59.531241Z","iopub.execute_input":"2022-06-15T05:22:59.531938Z","iopub.status.idle":"2022-06-15T05:23:00.055064Z","shell.execute_reply.started":"2022-06-15T05:22:59.53189Z","shell.execute_reply":"2022-06-15T05:23:00.053261Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Converting DataFrame to array\nx_train = x_train.to_numpy()\nx_test = x_test.to_numpy()","metadata":{"execution":{"iopub.status.busy":"2022-06-15T05:23:00.058477Z","iopub.execute_input":"2022-06-15T05:23:00.058794Z","iopub.status.idle":"2022-06-15T05:23:00.064584Z","shell.execute_reply.started":"2022-06-15T05:23:00.058745Z","shell.execute_reply":"2022-06-15T05:23:00.062471Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### Normalization / ಎಂದಿನಂತಾಗಿಸುವುದು¶\n","metadata":{}},{"cell_type":"code","source":"# Reshape and Normalization\nx_train = x_train.reshape(x_train.shape[0],28,28,1).astype('float64')/255\nx_test = x_test.reshape(x_test.shape[0],28,28,1).astype('float64')/255","metadata":{"execution":{"iopub.status.busy":"2022-06-15T05:23:00.065983Z","iopub.execute_input":"2022-06-15T05:23:00.066242Z","iopub.status.idle":"2022-06-15T05:23:00.240015Z","shell.execute_reply.started":"2022-06-15T05:23:00.066206Z","shell.execute_reply":"2022-06-15T05:23:00.239171Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(x_train.shape)\nprint(x_test.shape)","metadata":{"execution":{"iopub.status.busy":"2022-06-15T05:23:00.241291Z","iopub.execute_input":"2022-06-15T05:23:00.242644Z","iopub.status.idle":"2022-06-15T05:23:00.248237Z","shell.execute_reply.started":"2022-06-15T05:23:00.242602Z","shell.execute_reply":"2022-06-15T05:23:00.247311Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"\n## Visualization / ನೋಟ\n","metadata":{"execution":{"iopub.status.busy":"2022-03-19T07:48:31.653683Z","iopub.execute_input":"2022-03-19T07:48:31.653944Z","iopub.status.idle":"2022-03-19T07:48:31.671531Z","shell.execute_reply.started":"2022-03-19T07:48:31.653919Z","shell.execute_reply":"2022-03-19T07:48:31.67045Z"}}},{"cell_type":"code","source":"\nclass_names = [0,1,2,3,4,5,6,7,8,9]\nplt.figure(figsize = (15,15))\nfor k in range(10):\n    xx = x_train[y_train == k]\n    yy = y_train[y_train == k].reset_index()['label']\n    for i in range(10):\n        plt.subplot(10,10,k * 10 + i + 1)\n        plt.xticks([])\n        plt.yticks([])\n        plt.grid(False)\n        plt.imshow(xx[i][:,:,0],cmap = 'gray')\n        label_index = int(yy[i])\n        plt.title('{}. {}'.format(k,class_names[label_index]))\nplt.show()        \n\n","metadata":{"execution":{"iopub.status.busy":"2022-06-15T05:23:00.249847Z","iopub.execute_input":"2022-06-15T05:23:00.250228Z","iopub.status.idle":"2022-06-15T05:23:04.728671Z","shell.execute_reply.started":"2022-06-15T05:23:00.25019Z","shell.execute_reply":"2022-06-15T05:23:04.727873Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### Encoding Label Values / ಗುರುತು ಬೆಲೆಯನ್ನು ಗುಟ್ಟುಬರೆಯುವಿಕೆ","metadata":{}},{"cell_type":"code","source":"# to_categorical is used to perform one-hot encoding for label values\nfrom keras.utils import np_utils\ny_train1 = np_utils.to_categorical(y_train,10)\ny_test1 = np_utils.to_categorical(y_test,10)","metadata":{"execution":{"iopub.status.busy":"2022-06-15T05:23:04.72972Z","iopub.execute_input":"2022-06-15T05:23:04.729976Z","iopub.status.idle":"2022-06-15T05:23:10.017668Z","shell.execute_reply.started":"2022-06-15T05:23:04.729938Z","shell.execute_reply":"2022-06-15T05:23:10.016891Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":" plt.imshow(x_train[5])","metadata":{"execution":{"iopub.status.busy":"2022-06-15T05:23:10.019155Z","iopub.execute_input":"2022-06-15T05:23:10.019415Z","iopub.status.idle":"2022-06-15T05:23:10.22598Z","shell.execute_reply.started":"2022-06-15T05:23:10.019377Z","shell.execute_reply":"2022-06-15T05:23:10.225309Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### Note - Above image shows 5/೫ in Kannada for a row 5 selection.\n### ಮೇಲಗಡೆಯ ತಿಟ್ಟದಲ್ಲಿ ಕಾಣುವ ಎಣಿಕೆ ಕನ್ನಡ ನುಡಿಯಲ್ಲಿ ೫ ಆಗಿದೆ.","metadata":{"execution":{"iopub.status.busy":"2022-06-14T12:59:39.813401Z","iopub.execute_input":"2022-06-14T12:59:39.814297Z","iopub.status.idle":"2022-06-14T12:59:39.817686Z","shell.execute_reply.started":"2022-06-14T12:59:39.814247Z","shell.execute_reply":"2022-06-14T12:59:39.816795Z"}}},{"cell_type":"markdown","source":"#### Data Augumentation / ತಿಳಿಹುವನ್ನು ಹೆಚ್ಚಿಸುವಿಕೆ","metadata":{}},{"cell_type":"code","source":"# create more sample images using ImageDataGenerator.This ensures we have more data to train on. More info about function here: https://keras.io/preprocessing/image/\nfrom keras.preprocessing.image import ImageDataGenerator\nimagegen = ImageDataGenerator(\n        featurewise_center=False, \n        samplewise_center=False, \n        featurewise_std_normalization=False, \n        samplewise_std_normalization=False,\n        zca_whitening=False, \n        rotation_range=9, \n        zoom_range = 0.25,\n        width_shift_range=0.25,\n        height_shift_range=0.25, \n        horizontal_flip=False, \n        vertical_flip=False)\n\nimagegen.fit(x_train)","metadata":{"execution":{"iopub.status.busy":"2022-06-15T05:23:10.227436Z","iopub.execute_input":"2022-06-15T05:23:10.227948Z","iopub.status.idle":"2022-06-15T05:23:10.344054Z","shell.execute_reply.started":"2022-06-15T05:23:10.227906Z","shell.execute_reply":"2022-06-15T05:23:10.34333Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# importing DL packages / ಆಳವಾದ ಕಲಿಕೆಯಲ್ಲಿ ಬಳಸುವ ಕೆಲವೊಂದು ಕಟ್ಟುಗಳನ್ನು ಒಳತರುವುದು\nimport tensorflow as tf\nfrom tensorflow import keras\nfrom tensorflow.keras.models import Sequential\nfrom tensorflow.keras.layers import Flatten,Conv2D,MaxPooling2D,Dense,Dropout","metadata":{"execution":{"iopub.status.busy":"2022-06-15T05:23:10.345213Z","iopub.execute_input":"2022-06-15T05:23:10.345474Z","iopub.status.idle":"2022-06-15T05:23:10.859905Z","shell.execute_reply.started":"2022-06-15T05:23:10.345438Z","shell.execute_reply":"2022-06-15T05:23:10.858943Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"\n## Building CNN Model (With dropout) // ಸಿ ಎನ್ ಎನ್ ಎತ್ತುಗೆ ಕಟ್ಟುವಿಕೆ \n","metadata":{"execution":{"iopub.status.busy":"2022-03-19T08:00:46.119302Z","iopub.execute_input":"2022-03-19T08:00:46.119539Z","iopub.status.idle":"2022-03-19T08:00:46.123817Z","shell.execute_reply.started":"2022-03-19T08:00:46.119517Z","shell.execute_reply":"2022-03-19T08:00:46.122132Z"}}},{"cell_type":"code","source":"tf.random.set_seed(100)\ntf.keras.backend.clear_session()\nmodel = None\nmodel = Sequential()\nmodel.add(Conv2D(32,kernel_size=(3,3),input_shape=(28,28,1),activation = 'relu'))\nmodel.add(MaxPooling2D(pool_size = 2))\nmodel.add(Conv2D(64,kernel_size=(3,3),activation='relu'))\nmodel.add(MaxPooling2D(pool_size = 2))\nmodel.add(Dropout(0.25))\nmodel.add(Flatten())\nmodel.add(Dense(128,activation='relu'))# First Hidden Layer with fully connected\nmodel.add(Dense(64,activation='relu'))# First Hidden Layer with fully connected\nmodel.add(Dense(10,activation='softmax')) # Output layer for 10 classification","metadata":{"execution":{"iopub.status.busy":"2022-06-15T05:23:10.864801Z","iopub.execute_input":"2022-06-15T05:23:10.867375Z","iopub.status.idle":"2022-06-15T05:23:13.680978Z","shell.execute_reply.started":"2022-06-15T05:23:10.867329Z","shell.execute_reply":"2022-06-15T05:23:13.679977Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Train the model / ಎತ್ತುಗೆಯನ್ನು ಪಳಗಿಸು¶\n","metadata":{}},{"cell_type":"code","source":"model.compile(loss='categorical_crossentropy',optimizer = 'adam',metrics = ['accuracy'])\nmodel.summary()","metadata":{"execution":{"iopub.status.busy":"2022-06-15T05:23:13.682199Z","iopub.execute_input":"2022-06-15T05:23:13.682877Z","iopub.status.idle":"2022-06-15T05:23:13.70137Z","shell.execute_reply.started":"2022-06-15T05:23:13.68284Z","shell.execute_reply":"2022-06-15T05:23:13.700178Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"history = model.fit_generator(imagegen.flow(x_train,y_train1,batch_size=128),epochs=30,validation_data=(x_test,y_test1),verbose = 1)","metadata":{"execution":{"iopub.status.busy":"2022-06-15T05:23:13.702725Z","iopub.execute_input":"2022-06-15T05:23:13.70306Z","iopub.status.idle":"2022-06-15T05:31:19.265751Z","shell.execute_reply.started":"2022-06-15T05:23:13.703005Z","shell.execute_reply":"2022-06-15T05:31:19.264691Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Evaluation and Prediction / ಬೆಲೆತೂಗುವಿಕೆ ಮತ್ತು ಮುನ್ಹೊಳಹು","metadata":{}},{"cell_type":"code","source":"test_score = model.evaluate(x_test,y_test1)\ntrain_score = model.evaluate(x_train,y_train1)\nprint('\\n Train Accuracy : %4f' % (train_score[1]))\nprint('\\n Test Accuracy : %4f' % (test_score[1]))","metadata":{"execution":{"iopub.status.busy":"2022-06-15T05:31:19.267713Z","iopub.execute_input":"2022-06-15T05:31:19.268013Z","iopub.status.idle":"2022-06-15T05:31:20.703827Z","shell.execute_reply.started":"2022-06-15T05:31:19.267972Z","shell.execute_reply":"2022-06-15T05:31:20.702943Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"\n### Accuray and Error Graph / ಸರಿಮೆ ಮತ್ತು ತಪ್ಪುಗಳ ಮಾರ್ಪುತಿಟ್ಟ¶\n","metadata":{}},{"cell_type":"code","source":"train_accuracy = history.history['accuracy']\ntrain_loss = history.history['loss']\n\nval_accuracy = history.history['val_accuracy']\nval_loss = history.history['val_loss']\n\nepochs = range(len(train_accuracy))\nplt.plot(epochs,train_accuracy,'o-g',label='Train')\nplt.plot(epochs,val_accuracy,'o-b',label='Validation/Test')\nplt.title('Accuracy')\nplt.legend()\nplt.xlabel('Epochs')\nplt.ylabel('Accuracy')\n#plt.figure()\nplt.show()\n\nplt.plot(epochs,train_loss,'o-g',label='Train')\nplt.plot(epochs,val_loss,'o-r',label = 'Validation/Test')\nplt.title('Loss')\nplt.legend()\nplt.xlabel('Epochs')\nplt.ylabel('Loss')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-06-15T05:31:26.214206Z","iopub.execute_input":"2022-06-15T05:31:26.214477Z","iopub.status.idle":"2022-06-15T05:31:26.665927Z","shell.execute_reply.started":"2022-06-15T05:31:26.21444Z","shell.execute_reply":"2022-06-15T05:31:26.665155Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Confusion Matrix / ಗೊಂದಲ,ಎಕ್ಕ-ಸಕ್ಕ ಅಣೆ","metadata":{"execution":{"iopub.status.busy":"2022-06-14T13:14:30.922132Z","iopub.execute_input":"2022-06-14T13:14:30.922418Z","iopub.status.idle":"2022-06-14T13:14:30.926062Z","shell.execute_reply.started":"2022-06-14T13:14:30.922387Z","shell.execute_reply":"2022-06-14T13:14:30.925138Z"}}},{"cell_type":"code","source":"y_test_pred = model.predict(x_test)\ny_test_pred = np.argmax(y_test_pred,axis = 1)\ny_test_pred","metadata":{"execution":{"iopub.status.busy":"2022-06-15T05:31:26.667337Z","iopub.execute_input":"2022-06-15T05:31:26.667783Z","iopub.status.idle":"2022-06-15T05:31:27.538218Z","shell.execute_reply.started":"2022-06-15T05:31:26.667741Z","shell.execute_reply":"2022-06-15T05:31:27.537379Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_test1= np.argmax(y_test1,axis = 1)\ny_test1","metadata":{"execution":{"iopub.status.busy":"2022-06-15T05:31:27.539515Z","iopub.execute_input":"2022-06-15T05:31:27.540021Z","iopub.status.idle":"2022-06-15T05:31:27.550249Z","shell.execute_reply.started":"2022-06-15T05:31:27.539983Z","shell.execute_reply":"2022-06-15T05:31:27.549278Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"conf = confusion_matrix(y_test1,y_test_pred)\nconf = pd.DataFrame(conf,index = range(0,10),columns = range(0,10))\nconf","metadata":{"execution":{"iopub.status.busy":"2022-06-15T05:31:27.55159Z","iopub.execute_input":"2022-06-15T05:31:27.551968Z","iopub.status.idle":"2022-06-15T05:31:27.572232Z","shell.execute_reply.started":"2022-06-15T05:31:27.551929Z","shell.execute_reply":"2022-06-15T05:31:27.571449Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize = (7,7))\nsns.heatmap(conf,annot=True,cmap = plt.cm.Greens )\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-06-15T05:31:27.573548Z","iopub.execute_input":"2022-06-15T05:31:27.573875Z","iopub.status.idle":"2022-06-15T05:31:28.198722Z","shell.execute_reply.started":"2022-06-15T05:31:27.573837Z","shell.execute_reply":"2022-06-15T05:31:28.197978Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### Further investigation / ಮುಂದುವರಿದ ಆರಯ್ಯಿಕೆ","metadata":{}},{"cell_type":"code","source":"# Check Incorrectly Misclassified / ತಪ್ಪಾಗಿ ಹಂಚಿಕೆಯಾಗಿರುವುದನ್ನು ನೋಡಿ\nx = (y_test_pred - y_test1 != 0).tolist()\nx = [ i for i,l in enumerate(x) if l != False]\nfig,ax = plt.subplots(1,4,sharey=False,figsize = (12,12))\nfor i in range(4):\n    ax[i].imshow(x_test[x[i]][:,:,0])\n    ax[i].set_xlabel('Actual {}, Predicted {}'\n                     .format(y_test1[x[i]],y_test_pred[x[i]]))\nplt.show()\n","metadata":{"execution":{"iopub.status.busy":"2022-06-15T05:31:28.202888Z","iopub.execute_input":"2022-06-15T05:31:28.203438Z","iopub.status.idle":"2022-06-15T05:31:28.833584Z","shell.execute_reply.started":"2022-06-15T05:31:28.203404Z","shell.execute_reply":"2022-06-15T05:31:28.832784Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Check Correctly Classified / ಸರಿಯಾಗಿ ಹಂಚಿಕೆಯಾಗಿರುವುದನ್ನು ನೋಡಿ\nx = (y_test_pred - y_test1 == 0).tolist()\nx = [ i for i,l in enumerate(x) if l != False]\nfig,ax = plt.subplots(1,4,sharey=False,figsize = (12,12))\nfor i in range(4):\n    ax[i].imshow(x_test[x[i]][:,:,0])\n    ax[i].set_xlabel('Actual {}, Predicted {}'\n                     .format(y_test1[x[i]],y_test_pred[x[i]]))\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-06-15T05:31:28.834802Z","iopub.execute_input":"2022-06-15T05:31:28.83556Z","iopub.status.idle":"2022-06-15T05:31:29.265859Z","shell.execute_reply.started":"2022-06-15T05:31:28.835518Z","shell.execute_reply":"2022-06-15T05:31:29.265146Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Submission / ಸಲ್ಲಿಕೆ","metadata":{}},{"cell_type":"code","source":"test.head()","metadata":{"execution":{"iopub.status.busy":"2022-06-15T05:31:29.267026Z","iopub.execute_input":"2022-06-15T05:31:29.267643Z","iopub.status.idle":"2022-06-15T05:31:29.284636Z","shell.execute_reply.started":"2022-06-15T05:31:29.267603Z","shell.execute_reply":"2022-06-15T05:31:29.283657Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_id = test['id']\ntest = test.drop(['id'],axis=1)\ntest = test.to_numpy()\ntest = test.reshape(test.shape[0],28,28,1).astype('float64')/255\ntest.shape","metadata":{"execution":{"iopub.status.busy":"2022-06-15T05:31:29.285918Z","iopub.execute_input":"2022-06-15T05:31:29.286222Z","iopub.status.idle":"2022-06-15T05:31:29.323029Z","shell.execute_reply.started":"2022-06-15T05:31:29.286181Z","shell.execute_reply":"2022-06-15T05:31:29.322283Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred = model.predict(test)\ny_pred = np.argmax(y_pred,axis = 1) # Changing the prediction into labels","metadata":{"execution":{"iopub.status.busy":"2022-06-15T05:31:29.324154Z","iopub.execute_input":"2022-06-15T05:31:29.324528Z","iopub.status.idle":"2022-06-15T05:31:29.69698Z","shell.execute_reply.started":"2022-06-15T05:31:29.324478Z","shell.execute_reply":"2022-06-15T05:31:29.696167Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission = pd.DataFrame({ 'id': test_id,\n                            'label': y_pred })\nsubmission.to_csv(\"submission.csv\", index=False)\nsubmission.head()","metadata":{"execution":{"iopub.status.busy":"2022-06-15T05:31:29.698526Z","iopub.execute_input":"2022-06-15T05:31:29.698787Z","iopub.status.idle":"2022-06-15T05:31:29.720242Z","shell.execute_reply.started":"2022-06-15T05:31:29.698751Z","shell.execute_reply":"2022-06-15T05:31:29.719378Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"\n### CNN model is better for image classification.\n### CNN test accuracy : 99%\n### ತಿಟ್ಟ ಹಂಚಿಕೆಗೆ CNN ಎತ್ತುಗೆ ಒಳ್ಳೆಯದಾಗಿದೆ.\n### CNN ಒರೆತದ ಸರಿಮೆ: ೯೯%\n    \n### Please upvote this notebook if you find anything helpful !! Thank you\n### ಇ ನನ್ನ ಹೊತ್ತಿಗೆಯಿಂದ ನಿಮಗೇ ಏನಾದರು ನೆರವಾಗಿದ್ದಾರೆ ದಯವಿಟ್ಟು ಮೇಲೆ ಬಲಗಡೆಯಲ್ಲಿ ಕಾಣುವ upvote ಬಟನ್ ಅನ್ನು ಹೊತ್ತಿ. ನನ್ನಿ !!","metadata":{}}]}