{"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":"2023-08-18T12:35:11.874341Z","iopub.execute_input":"2023-08-18T12:35:11.875418Z","iopub.status.idle":"2023-08-18T12:35:11.910348Z","shell.execute_reply.started":"2023-08-18T12:35:11.875379Z","shell.execute_reply":"2023-08-18T12:35:11.909198Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import os\nimport numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nsns.set()\n%matplotlib inline\n\nimport warnings\nwarnings.filterwarnings('ignore')","metadata":{"execution":{"iopub.status.busy":"2023-08-18T12:35:11.912186Z","iopub.execute_input":"2023-08-18T12:35:11.912530Z","iopub.status.idle":"2023-08-18T12:35:13.349118Z","shell.execute_reply.started":"2023-08-18T12:35:11.912502Z","shell.execute_reply":"2023-08-18T12:35:13.348078Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#  Import data","metadata":{}},{"cell_type":"code","source":"import os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))","metadata":{"execution":{"iopub.status.busy":"2023-08-18T12:35:13.350921Z","iopub.execute_input":"2023-08-18T12:35:13.351258Z","iopub.status.idle":"2023-08-18T12:35:13.357991Z","shell.execute_reply.started":"2023-08-18T12:35:13.351230Z","shell.execute_reply":"2023-08-18T12:35:13.356906Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = pd.read_csv('/kaggle/input/digit-recognizer/train.csv')\ntest = pd.read_csv('/kaggle/input/digit-recognizer/test.csv')","metadata":{"execution":{"iopub.status.busy":"2023-08-18T12:35:13.360229Z","iopub.execute_input":"2023-08-18T12:35:13.361308Z","iopub.status.idle":"2023-08-18T12:35:20.443222Z","shell.execute_reply.started":"2023-08-18T12:35:13.361266Z","shell.execute_reply":"2023-08-18T12:35:20.442039Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.head()","metadata":{"execution":{"iopub.status.busy":"2023-08-18T12:35:20.444598Z","iopub.execute_input":"2023-08-18T12:35:20.445051Z","iopub.status.idle":"2023-08-18T12:35:20.474893Z","shell.execute_reply.started":"2023-08-18T12:35:20.445011Z","shell.execute_reply":"2023-08-18T12:35:20.473747Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test.head()","metadata":{"execution":{"iopub.status.busy":"2023-08-18T12:35:20.476055Z","iopub.execute_input":"2023-08-18T12:35:20.476359Z","iopub.status.idle":"2023-08-18T12:35:20.495983Z","shell.execute_reply.started":"2023-08-18T12:35:20.476333Z","shell.execute_reply":"2023-08-18T12:35:20.494669Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.info()","metadata":{"execution":{"iopub.status.busy":"2023-08-18T12:35:20.497936Z","iopub.execute_input":"2023-08-18T12:35:20.498401Z","iopub.status.idle":"2023-08-18T12:35:20.564753Z","shell.execute_reply.started":"2023-08-18T12:35:20.498350Z","shell.execute_reply":"2023-08-18T12:35:20.563536Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test.info()","metadata":{"execution":{"iopub.status.busy":"2023-08-18T12:35:20.566208Z","iopub.execute_input":"2023-08-18T12:35:20.566562Z","iopub.status.idle":"2023-08-18T12:35:20.611353Z","shell.execute_reply.started":"2023-08-18T12:35:20.566533Z","shell.execute_reply":"2023-08-18T12:35:20.609680Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.describe()","metadata":{"execution":{"iopub.status.busy":"2023-08-18T12:35:20.612828Z","iopub.execute_input":"2023-08-18T12:35:20.613244Z","iopub.status.idle":"2023-08-18T12:35:23.469308Z","shell.execute_reply.started":"2023-08-18T12:35:20.613212Z","shell.execute_reply":"2023-08-18T12:35:23.468116Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test.describe()","metadata":{"execution":{"iopub.status.busy":"2023-08-18T12:35:23.474821Z","iopub.execute_input":"2023-08-18T12:35:23.475927Z","iopub.status.idle":"2023-08-18T12:35:25.866001Z","shell.execute_reply.started":"2023-08-18T12:35:23.475879Z","shell.execute_reply":"2023-08-18T12:35:25.864816Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.shape","metadata":{"execution":{"iopub.status.busy":"2023-08-18T12:35:25.867408Z","iopub.execute_input":"2023-08-18T12:35:25.868016Z","iopub.status.idle":"2023-08-18T12:35:25.874368Z","shell.execute_reply.started":"2023-08-18T12:35:25.867984Z","shell.execute_reply":"2023-08-18T12:35:25.873192Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test.shape","metadata":{"execution":{"iopub.status.busy":"2023-08-18T12:35:25.876276Z","iopub.execute_input":"2023-08-18T12:35:25.876708Z","iopub.status.idle":"2023-08-18T12:35:25.890314Z","shell.execute_reply.started":"2023-08-18T12:35:25.876668Z","shell.execute_reply":"2023-08-18T12:35:25.889327Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(train.shape,test.shape)","metadata":{"execution":{"iopub.status.busy":"2023-08-18T12:35:25.892159Z","iopub.execute_input":"2023-08-18T12:35:25.892546Z","iopub.status.idle":"2023-08-18T12:35:25.905842Z","shell.execute_reply.started":"2023-08-18T12:35:25.892501Z","shell.execute_reply":"2023-08-18T12:35:25.903788Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#  Data preprocessing","metadata":{}},{"cell_type":"markdown","source":"** Missing value treatment**","metadata":{}},{"cell_type":"code","source":"train.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2023-08-18T12:35:25.907344Z","iopub.execute_input":"2023-08-18T12:35:25.907922Z","iopub.status.idle":"2023-08-18T12:35:25.948152Z","shell.execute_reply.started":"2023-08-18T12:35:25.907882Z","shell.execute_reply":"2023-08-18T12:35:25.946837Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"*  No missing values","metadata":{}},{"cell_type":"code","source":"test.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2023-08-18T12:35:25.949750Z","iopub.execute_input":"2023-08-18T12:35:25.950217Z","iopub.status.idle":"2023-08-18T12:35:25.978372Z","shell.execute_reply.started":"2023-08-18T12:35:25.950167Z","shell.execute_reply":"2023-08-18T12:35:25.977163Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"*  No missing values","metadata":{}},{"cell_type":"code","source":"train.head()","metadata":{"execution":{"iopub.status.busy":"2023-08-18T12:35:25.980099Z","iopub.execute_input":"2023-08-18T12:35:25.980492Z","iopub.status.idle":"2023-08-18T12:35:26.000192Z","shell.execute_reply.started":"2023-08-18T12:35:25.980457Z","shell.execute_reply":"2023-08-18T12:35:25.999027Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data =train.loc[:,\"pixel0\":]\ntrain_label = train.loc[:\"label\"]","metadata":{"execution":{"iopub.status.busy":"2023-08-18T12:35:26.001857Z","iopub.execute_input":"2023-08-18T12:35:26.002910Z","iopub.status.idle":"2023-08-18T12:35:26.064693Z","shell.execute_reply.started":"2023-08-18T12:35:26.002867Z","shell.execute_reply":"2023-08-18T12:35:26.063610Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data = train_data/255.0\ntest = test/255.0","metadata":{"execution":{"iopub.status.busy":"2023-08-18T12:35:26.066184Z","iopub.execute_input":"2023-08-18T12:35:26.066612Z","iopub.status.idle":"2023-08-18T12:35:26.221902Z","shell.execute_reply.started":"2023-08-18T12:35:26.066581Z","shell.execute_reply":"2023-08-18T12:35:26.220926Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data.head()","metadata":{"execution":{"iopub.status.busy":"2023-08-18T12:35:26.222895Z","iopub.execute_input":"2023-08-18T12:35:26.223322Z","iopub.status.idle":"2023-08-18T12:35:26.261126Z","shell.execute_reply.started":"2023-08-18T12:35:26.223283Z","shell.execute_reply":"2023-08-18T12:35:26.260292Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test.head()","metadata":{"execution":{"iopub.status.busy":"2023-08-18T12:35:26.262526Z","iopub.execute_input":"2023-08-18T12:35:26.263507Z","iopub.status.idle":"2023-08-18T12:35:26.298505Z","shell.execute_reply.started":"2023-08-18T12:35:26.263472Z","shell.execute_reply":"2023-08-18T12:35:26.297355Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"digit_array = train.loc[3,\"pixel0\":]\narr = np.array(digit_array)\n\nimage_array = np.reshape(arr,(28,28))\n\n\ndigit_img = plt.imshow(image_array,cmap = plt.cm.binary)\nplt.colorbar(digit_img)\nprint(\"IMAGE LABEL.{}\".format(train.loc[3,\"label\"]))","metadata":{"execution":{"iopub.status.busy":"2023-08-18T12:37:16.934914Z","iopub.execute_input":"2023-08-18T12:37:16.935323Z","iopub.status.idle":"2023-08-18T12:37:17.462907Z","shell.execute_reply.started":"2023-08-18T12:37:16.935293Z","shell.execute_reply":"2023-08-18T12:37:17.461711Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"execution":{"iopub.status.busy":"2023-08-18T13:15:03.148182Z","iopub.execute_input":"2023-08-18T13:15:03.148578Z","iopub.status.idle":"2023-08-18T13:15:19.523194Z","shell.execute_reply.started":"2023-08-18T13:15:03.148547Z","shell.execute_reply":"2023-08-18T13:15:19.522056Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"execution":{"iopub.status.busy":"2023-08-18T13:11:43.880389Z","iopub.status.idle":"2023-08-18T13:11:43.880784Z","shell.execute_reply.started":"2023-08-18T13:11:43.880586Z","shell.execute_reply":"2023-08-18T13:11:43.880603Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}