{"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-13T05:51:55.518481Z","iopub.execute_input":"2023-08-13T05:51:55.518881Z","iopub.status.idle":"2023-08-13T05:51:55.528490Z","shell.execute_reply.started":"2023-08-13T05:51:55.518847Z","shell.execute_reply":"2023-08-13T05:51:55.527444Z"},"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-13T05:51:55.530087Z","iopub.execute_input":"2023-08-13T05:51:55.531028Z","iopub.status.idle":"2023-08-13T05:51:59.323030Z","shell.execute_reply.started":"2023-08-13T05:51:55.530985Z","shell.execute_reply":"2023-08-13T05:51:59.322109Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.head(10)\n","metadata":{"execution":{"iopub.status.busy":"2023-08-13T05:51:59.324849Z","iopub.execute_input":"2023-08-13T05:51:59.325163Z","iopub.status.idle":"2023-08-13T05:51:59.344242Z","shell.execute_reply.started":"2023-08-13T05:51:59.325136Z","shell.execute_reply":"2023-08-13T05:51:59.343114Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test.head(10)","metadata":{"execution":{"iopub.status.busy":"2023-08-13T05:51:59.345631Z","iopub.execute_input":"2023-08-13T05:51:59.346215Z","iopub.status.idle":"2023-08-13T05:51:59.364712Z","shell.execute_reply.started":"2023-08-13T05:51:59.346184Z","shell.execute_reply":"2023-08-13T05:51:59.363691Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.info()","metadata":{"execution":{"iopub.status.busy":"2023-08-13T05:51:59.367083Z","iopub.execute_input":"2023-08-13T05:51:59.367579Z","iopub.status.idle":"2023-08-13T05:51:59.408354Z","shell.execute_reply.started":"2023-08-13T05:51:59.367549Z","shell.execute_reply":"2023-08-13T05:51:59.407230Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.shape","metadata":{"execution":{"iopub.status.busy":"2023-08-13T05:51:59.409851Z","iopub.execute_input":"2023-08-13T05:51:59.410297Z","iopub.status.idle":"2023-08-13T05:51:59.418607Z","shell.execute_reply.started":"2023-08-13T05:51:59.410240Z","shell.execute_reply":"2023-08-13T05:51:59.417490Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nnum = np.array(train.iloc[3,1:]).reshape(28,28)\n\nplt.imshow(num)\nplt.show()\n","metadata":{"execution":{"iopub.status.busy":"2023-08-13T05:51:59.419866Z","iopub.execute_input":"2023-08-13T05:51:59.420175Z","iopub.status.idle":"2023-08-13T05:51:59.634395Z","shell.execute_reply.started":"2023-08-13T05:51:59.420148Z","shell.execute_reply":"2023-08-13T05:51:59.633562Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"arr =train.iloc[3,1:]","metadata":{"execution":{"iopub.status.busy":"2023-08-13T05:51:59.635516Z","iopub.execute_input":"2023-08-13T05:51:59.636289Z","iopub.status.idle":"2023-08-13T05:51:59.641685Z","shell.execute_reply.started":"2023-08-13T05:51:59.636261Z","shell.execute_reply":"2023-08-13T05:51:59.640442Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.hist(arr)","metadata":{"execution":{"iopub.status.busy":"2023-08-13T05:51:59.643381Z","iopub.execute_input":"2023-08-13T05:51:59.643809Z","iopub.status.idle":"2023-08-13T05:51:59.898452Z","shell.execute_reply.started":"2023-08-13T05:51:59.643763Z","shell.execute_reply":"2023-08-13T05:51:59.897454Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"missing_value = test.isnull().sum()\nmissing_value","metadata":{"execution":{"iopub.status.busy":"2023-08-13T05:51:59.899867Z","iopub.execute_input":"2023-08-13T05:51:59.900287Z","iopub.status.idle":"2023-08-13T05:51:59.927946Z","shell.execute_reply.started":"2023-08-13T05:51:59.900235Z","shell.execute_reply":"2023-08-13T05:51:59.926988Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## FEATURE ENGG","metadata":{}},{"cell_type":"code","source":"x = np.array(train)\ny = np.array(test)\n\nx_train = x[:,1:]\ny_train = x[:,0]\n\nx_test = y","metadata":{"execution":{"iopub.status.busy":"2023-08-13T05:51:59.930799Z","iopub.execute_input":"2023-08-13T05:51:59.931104Z","iopub.status.idle":"2023-08-13T05:52:00.149580Z","shell.execute_reply.started":"2023-08-13T05:51:59.931077Z","shell.execute_reply":"2023-08-13T05:52:00.148456Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from keras.preprocessing.image import ImageDataGenerator\nx_train = x_train.reshape(-1,28,28,1)","metadata":{"execution":{"iopub.status.busy":"2023-08-13T05:52:00.150811Z","iopub.execute_input":"2023-08-13T05:52:00.151198Z","iopub.status.idle":"2023-08-13T05:52:00.155449Z","shell.execute_reply.started":"2023-08-13T05:52:00.151171Z","shell.execute_reply":"2023-08-13T05:52:00.154739Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"datagen = ImageDataGenerator(\n    rotation_range = 15,\n    height_shift_range = 0.1,\n    zoom_range = 0.1,\n    shear_range = 0.1,\n)\n\ndatagen.fit(x_train)","metadata":{"execution":{"iopub.status.busy":"2023-08-13T05:52:00.156368Z","iopub.execute_input":"2023-08-13T05:52:00.157176Z","iopub.status.idle":"2023-08-13T05:52:00.308790Z","shell.execute_reply.started":"2023-08-13T05:52:00.157146Z","shell.execute_reply":"2023-08-13T05:52:00.307667Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_train = x_train.reshape(-1,784)","metadata":{"execution":{"iopub.status.busy":"2023-08-13T05:52:00.310043Z","iopub.execute_input":"2023-08-13T05:52:00.310367Z","iopub.status.idle":"2023-08-13T05:52:00.315756Z","shell.execute_reply.started":"2023-08-13T05:52:00.310340Z","shell.execute_reply":"2023-08-13T05:52:00.314722Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.neighbors import KNeighborsClassifier","metadata":{"execution":{"iopub.status.busy":"2023-08-13T05:52:00.317025Z","iopub.execute_input":"2023-08-13T05:52:00.317334Z","iopub.status.idle":"2023-08-13T05:52:00.332574Z","shell.execute_reply.started":"2023-08-13T05:52:00.317307Z","shell.execute_reply":"2023-08-13T05:52:00.331422Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"knn = KNeighborsClassifier(n_neighbors = 5)\nknn.fit(x_train,y_train)","metadata":{"execution":{"iopub.status.busy":"2023-08-13T05:52:00.334458Z","iopub.execute_input":"2023-08-13T05:52:00.334873Z","iopub.status.idle":"2023-08-13T05:52:00.470821Z","shell.execute_reply.started":"2023-08-13T05:52:00.334836Z","shell.execute_reply":"2023-08-13T05:52:00.469754Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"int(knn.predict(x_test[105].reshape(1,-1)))","metadata":{"execution":{"iopub.status.busy":"2023-08-13T05:52:00.473471Z","iopub.execute_input":"2023-08-13T05:52:00.474157Z","iopub.status.idle":"2023-08-13T05:52:00.661788Z","shell.execute_reply.started":"2023-08-13T05:52:00.474119Z","shell.execute_reply":"2023-08-13T05:52:00.660423Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"num = np.array(test.iloc[105,:]).reshape(28,28)\nplt.imshow(num)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-08-13T05:52:00.663612Z","iopub.execute_input":"2023-08-13T05:52:00.664314Z","iopub.status.idle":"2023-08-13T05:52:00.891737Z","shell.execute_reply.started":"2023-08-13T05:52:00.664271Z","shell.execute_reply":"2023-08-13T05:52:00.890559Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}