{"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":"<center><img src='data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAoHCBISEhgREhISERIREhEREREREREPERERGBgZGRoUGBgcIS4lHB4sHxgYJjgmLC8xNTU1GiQ7QDs0QC40NTEBDAwMBgYGEAYGEDEdFh0xMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMf/AABEIAKgBKwMBIgACEQEDEQH/xAAcAAACAwEBAQEAAAAAAAAAAAAAAwECBAUGBwj/xABLEAACAgIBAgMEBAYLEQEBAAABAgADBBESBSETMUEGIlFhFDJxgTNCUpGhsgcjJDRTYnJ0krHBFURUZHOCg4STlKK0wsPR0uFDJf/EABQBAQAAAAAAAAAAAAAAAAAAAAD/xAAUEQEAAAAAAAAAAAAAAAAAAAAA/9oADAMBAAIRAxEAPwDqKsciyEWaFWBKLHIkhBuaEWBKJ8o5VllrPwjVrPwP26gVVYxUlkWMVYEKssqSQsYsCOMsqyyyQIFSsOMZqECgWGowCECmoal+UOUCmoal+UOUCmoal+UIC9SCsbqRAXxlCscTIKwEFZXjHlJBEDOyxTJNLLFlNwMxWLZZbIzKU7PbUh+D21oR9xMiu1LPwdldg/iOj/1EwEOkzuk3OsS6QMLrEOk1usS6QMTLF8ZqdYnUDXWk0Km5RBJyshaa3ufutVdljD1IRS2vv1r74GfO6kKWWqutr8hwWShCAeI/Hdz2RP4x8/QGQnScq7vk5T1j/B8H9zoB+S1p27faOMZ7OdPKV+LZ3ycrjbkP68mG1rHwRAQoHy36znXe3FK3PRXj5WR4D8LXprDBWBKnS75EbBG9DygdJPZPAP18ZbT+VdZde2/tZzHL7J4Y/B12Y59GxsjIx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bJ2SdeZJ9fOOhCAQhCBBkSTIgTCRJgVaUliZWBJMW8uZRjAoTEuY1ol4C3MVLWRe4FlmlZEIDUMYphCBcS4hCAblxCEAhCEAkgwhAmEIQCEIQCEIQCEIQCEIQCEIQCQYQgRCEIEyCYQgUgIQgVaLaEIC2MW5kQgIYxXKEIH//2Q==' width = '600px'></center>","metadata":{}},{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\nimport seaborn as sns\nimport matplotlib.pyplot as plt\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.metrics import accuracy_score\nfrom lightgbm import LGBMClassifier\nimport tensorflow as tf\nfrom tensorflow import keras\nimport warnings\nwarnings.filterwarnings('ignore')","metadata":{"execution":{"iopub.status.busy":"2021-06-14T18:24:38.262683Z","iopub.execute_input":"2021-06-14T18:24:38.263171Z","iopub.status.idle":"2021-06-14T18:24:46.918880Z","shell.execute_reply.started":"2021-06-14T18:24:38.263079Z","shell.execute_reply":"2021-06-14T18:24:46.917879Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<h1 id=\"heading1\">\n<span style=\"font-size:30px;color:#800080\"><center>Loading Data</center></span>\n<a class=\"anchor-link\" href=\"https://www.kaggle.com/alampalsingh/notebook004d896e8c#heading1\" target ='_self'></a>\n</h1>","metadata":{}},{"cell_type":"code","source":"df = pd.read_csv('../input/digit-recognizer/train.csv')\ntest = pd.read_csv('../input/digit-recognizer/test.csv')","metadata":{"execution":{"iopub.status.busy":"2021-06-14T18:24:46.920415Z","iopub.execute_input":"2021-06-14T18:24:46.920729Z","iopub.status.idle":"2021-06-14T18:24:52.387238Z","shell.execute_reply.started":"2021-06-14T18:24:46.920695Z","shell.execute_reply":"2021-06-14T18:24:52.386271Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df","metadata":{"execution":{"iopub.status.busy":"2021-06-14T18:24:52.388931Z","iopub.execute_input":"2021-06-14T18:24:52.389235Z","iopub.status.idle":"2021-06-14T18:24:52.423649Z","shell.execute_reply.started":"2021-06-14T18:24:52.389207Z","shell.execute_reply":"2021-06-14T18:24:52.422673Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test","metadata":{"execution":{"iopub.status.busy":"2021-06-14T18:24:52.425473Z","iopub.execute_input":"2021-06-14T18:24:52.425888Z","iopub.status.idle":"2021-06-14T18:24:52.449036Z","shell.execute_reply.started":"2021-06-14T18:24:52.425851Z","shell.execute_reply":"2021-06-14T18:24:52.448075Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<h1 id=\"heading2\">\n<span style=\"font-size:30px;color:#800080\"><center>Visual Representation of data.</center></span>\n<a class=\"anchor-link\" href=\"https://www.kaggle.com/alampalsingh/notebook004d896e8c#heading2\" target ='_self'></a>\n</h1>\n<span style=\"font-size:15px;\"><center>*As we have data of a 28x28 matrix in a flatten form.*</center></span>","metadata":{}},{"cell_type":"code","source":"arr = []\nfor i in range (1,df.shape[1]):\n    arr.append(df.iloc[3,i])#Collecting data of a certain image.\narr = np.asarray(arr)\narr = arr.reshape(28,28)#Reshape in 28x28 matrix.\nplt.imshow(arr)","metadata":{"execution":{"iopub.status.busy":"2021-06-14T18:24:52.450592Z","iopub.execute_input":"2021-06-14T18:24:52.450965Z","iopub.status.idle":"2021-06-14T18:24:52.619102Z","shell.execute_reply.started":"2021-06-14T18:24:52.450927Z","shell.execute_reply":"2021-06-14T18:24:52.618175Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.label[3]","metadata":{"execution":{"iopub.status.busy":"2021-06-14T18:24:52.620516Z","iopub.execute_input":"2021-06-14T18:24:52.620869Z","iopub.status.idle":"2021-06-14T18:24:52.627273Z","shell.execute_reply.started":"2021-06-14T18:24:52.620833Z","shell.execute_reply":"2021-06-14T18:24:52.626437Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Splitting the data in train and test set**","metadata":{}},{"cell_type":"code","source":"x = df.drop([\"label\"],axis =1)","metadata":{"execution":{"iopub.status.busy":"2021-06-14T18:24:52.628676Z","iopub.execute_input":"2021-06-14T18:24:52.629214Z","iopub.status.idle":"2021-06-14T18:24:52.712691Z","shell.execute_reply.started":"2021-06-14T18:24:52.629178Z","shell.execute_reply":"2021-06-14T18:24:52.711622Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y = df.label","metadata":{"execution":{"iopub.status.busy":"2021-06-14T18:24:52.715917Z","iopub.execute_input":"2021-06-14T18:24:52.716321Z","iopub.status.idle":"2021-06-14T18:24:52.725615Z","shell.execute_reply.started":"2021-06-14T18:24:52.716282Z","shell.execute_reply":"2021-06-14T18:24:52.724740Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_train,x_test,y_train,y_test = train_test_split(x,y,test_size=0.2,random_state=42)","metadata":{"execution":{"iopub.status.busy":"2021-06-14T18:24:52.727072Z","iopub.execute_input":"2021-06-14T18:24:52.727372Z","iopub.status.idle":"2021-06-14T18:24:52.969492Z","shell.execute_reply.started":"2021-06-14T18:24:52.727336Z","shell.execute_reply":"2021-06-14T18:24:52.968444Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<h1 id=\"heading4\">\n<span style=\"font-size:30px;color:#800080\"><center>LightGBM</center></span>\n<a class=\"anchor-link\" href=\"https://www.kaggle.com/alampalsingh/notebook004d896e8c#heading4\" target ='_self'></a>\n</h1>","metadata":{}},{"cell_type":"code","source":"lgb = LGBMClassifier()\nlgb.fit(x_train,y_train)\naccuracy_score(y_test,lgb.predict(x_test))","metadata":{"execution":{"iopub.status.busy":"2021-06-14T18:24:52.971557Z","iopub.execute_input":"2021-06-14T18:24:52.971812Z","iopub.status.idle":"2021-06-14T18:26:15.233524Z","shell.execute_reply.started":"2021-06-14T18:24:52.971785Z","shell.execute_reply":"2021-06-14T18:26:15.232637Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<h1 id=\"heading5\">\n<span style=\"font-size:30px;color:#800080\"><center>Keras</center></span>\n<a class=\"anchor-link\" href=\"https://www.kaggle.com/alampalsingh/notebook004d896e8c#heading5\" target ='_self'></a>\n</h1>","metadata":{}},{"cell_type":"code","source":"model = keras.models.Sequential()\nmodel.add(keras.layers.Dense(500,input_dim = 784,kernel_initializer= \"uniform\", \n  bias_initializer= \"zeros\",activation='relu'))\nmodel.add(keras.layers.Dropout(0.3))\nmodel.add(keras.layers.Dense(300,kernel_initializer= \"uniform\", \n  bias_initializer= \"zeros\",activation='relu'))\nmodel.add(keras.layers.Dropout(0.3))\nmodel.add(keras.layers.Dense(100,kernel_initializer= \"uniform\", \n  bias_initializer= \"zeros\",activation='relu'))\nmodel.add(keras.layers.Dropout(0.3))\nmodel.add(keras.layers.Dense(50,kernel_initializer= \"uniform\", \n  bias_initializer= \"zeros\",activation='relu'))\nmodel.add(keras.layers.Dropout(0.3))\nmodel.add(keras.layers.Dense(10,kernel_initializer= \"uniform\", \n  bias_initializer= \"zeros\",activation='softmax'))","metadata":{"execution":{"iopub.status.busy":"2021-06-14T18:26:15.236479Z","iopub.execute_input":"2021-06-14T18:26:15.236751Z","iopub.status.idle":"2021-06-14T18:26:17.288499Z","shell.execute_reply.started":"2021-06-14T18:26:15.236724Z","shell.execute_reply":"2021-06-14T18:26:17.287653Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.summary()","metadata":{"execution":{"iopub.status.busy":"2021-06-14T18:26:17.289644Z","iopub.execute_input":"2021-06-14T18:26:17.289967Z","iopub.status.idle":"2021-06-14T18:26:17.302337Z","shell.execute_reply.started":"2021-06-14T18:26:17.289935Z","shell.execute_reply":"2021-06-14T18:26:17.301613Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"weights, biases = model.layers[0].get_weights()\nweights.shape,biases.shape","metadata":{"execution":{"iopub.status.busy":"2021-06-14T18:26:17.303409Z","iopub.execute_input":"2021-06-14T18:26:17.303732Z","iopub.status.idle":"2021-06-14T18:26:17.322091Z","shell.execute_reply.started":"2021-06-14T18:26:17.303699Z","shell.execute_reply":"2021-06-14T18:26:17.320837Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.compile(loss = 'sparse_categorical_crossentropy',optimizer = \"sgd\",metrics=[\"accuracy\"])","metadata":{"execution":{"iopub.status.busy":"2021-06-14T18:26:17.323400Z","iopub.execute_input":"2021-06-14T18:26:17.323896Z","iopub.status.idle":"2021-06-14T18:26:17.340024Z","shell.execute_reply.started":"2021-06-14T18:26:17.323857Z","shell.execute_reply":"2021-06-14T18:26:17.339289Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_train = x_train/255.# values are between range of 0 to 255. To normalize divide it bby 255.\nx_test = x_test/255.","metadata":{"execution":{"iopub.status.busy":"2021-06-14T18:26:17.341194Z","iopub.execute_input":"2021-06-14T18:26:17.341791Z","iopub.status.idle":"2021-06-14T18:26:17.448781Z","shell.execute_reply.started":"2021-06-14T18:26:17.341752Z","shell.execute_reply":"2021-06-14T18:26:17.447853Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model_history = model.fit(x_train,y_train,epochs=80,validation_data=(x_test,y_test))","metadata":{"execution":{"iopub.status.busy":"2021-06-14T18:26:17.450015Z","iopub.execute_input":"2021-06-14T18:26:17.450431Z","iopub.status.idle":"2021-06-14T18:29:36.158210Z","shell.execute_reply.started":"2021-06-14T18:26:17.450388Z","shell.execute_reply":"2021-06-14T18:29:36.157133Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<h1 id=\"heading6\">\n<span style=\"font-size:30px;color:#800080\"><center>Model's Progress</center></span>\n<a class=\"anchor-link\" href=\"https://www.kaggle.com/alampalsingh/notebook004d896e8c#heading6\" target ='_self'></a>\n</h1>","metadata":{}},{"cell_type":"code","source":"pd.DataFrame(model_history.history).plot(figsize=(20,6))\nplt.grid(True)\nplt.gca().set_ylim(0,1)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2021-06-14T18:29:36.159803Z","iopub.execute_input":"2021-06-14T18:29:36.160346Z","iopub.status.idle":"2021-06-14T18:29:36.388576Z","shell.execute_reply.started":"2021-06-14T18:29:36.160306Z","shell.execute_reply":"2021-06-14T18:29:36.387774Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test = test/255.","metadata":{"execution":{"iopub.status.busy":"2021-06-14T18:29:36.389795Z","iopub.execute_input":"2021-06-14T18:29:36.390120Z","iopub.status.idle":"2021-06-14T18:29:36.460126Z","shell.execute_reply.started":"2021-06-14T18:29:36.390084Z","shell.execute_reply":"2021-06-14T18:29:36.459298Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Predicting class of the test data.**","metadata":{}},{"cell_type":"code","source":"pred = model.predict_classes(test)\npred = pred.round(2)","metadata":{"execution":{"iopub.status.busy":"2021-06-14T18:29:36.461535Z","iopub.execute_input":"2021-06-14T18:29:36.461895Z","iopub.status.idle":"2021-06-14T18:29:37.431406Z","shell.execute_reply.started":"2021-06-14T18:29:36.461858Z","shell.execute_reply":"2021-06-14T18:29:37.430543Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<h1 id=\"heading7\">\n<span style=\"font-size:30px;color:#800080\"><center>Comparing predicted and actual digit using visualization.</center></span>\n<a class=\"anchor-link\" href=\"https://www.kaggle.com/alampalsingh/notebook004d896e8c#heading7\" target ='_self'></a>\n</h1>","metadata":{}},{"cell_type":"code","source":"pred[0]","metadata":{"execution":{"iopub.status.busy":"2021-06-14T18:29:37.432767Z","iopub.execute_input":"2021-06-14T18:29:37.433106Z","iopub.status.idle":"2021-06-14T18:29:37.438285Z","shell.execute_reply.started":"2021-06-14T18:29:37.433059Z","shell.execute_reply":"2021-06-14T18:29:37.437486Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"arr = []\nfor i in range (0,test.shape[1]):\n    arr.append(test.iloc[0,i])\narr = np.asarray(arr)\narr = arr.reshape(28,28)\nplt.imshow(arr)","metadata":{"execution":{"iopub.status.busy":"2021-06-14T18:29:37.439518Z","iopub.execute_input":"2021-06-14T18:29:37.440130Z","iopub.status.idle":"2021-06-14T18:29:37.586070Z","shell.execute_reply.started":"2021-06-14T18:29:37.440095Z","shell.execute_reply":"2021-06-14T18:29:37.585289Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred = pd.DataFrame(pred)\nidx = np.arange(1,28001)\nidx = pd.DataFrame(idx)\nsub = pd.concat([idx,pred],axis = 1)\nsub.columns = ['ImageId','Label']\nsub.to_csv('submission.csv',index = False)","metadata":{"execution":{"iopub.status.busy":"2021-06-14T18:29:37.587459Z","iopub.execute_input":"2021-06-14T18:29:37.587812Z","iopub.status.idle":"2021-06-14T18:29:37.645114Z","shell.execute_reply.started":"2021-06-14T18:29:37.587775Z","shell.execute_reply":"2021-06-14T18:29:37.644338Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<center><span style=\"font-size:25px;color:#9ACD32;font-weight:bold\">If you find this notebook helpful, don't forget to </span><span style= 'font-size:25px;color:#b7410e;font-weight:bold'>upvote.","metadata":{}},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}