{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.14","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":3004,"databundleVersionId":861823,"sourceType":"competition"}],"dockerImageVersionId":30775,"isInternetEnabled":false,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"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":"2024-10-03T02:47:17.215786Z","iopub.execute_input":"2024-10-03T02:47:17.216722Z","iopub.status.idle":"2024-10-03T02:47:18.442422Z","shell.execute_reply.started":"2024-10-03T02:47:17.216676Z","shell.execute_reply":"2024-10-03T02:47:18.441055Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.read_csv('/kaggle/input/digit-recognizer/train.csv')","metadata":{"execution":{"iopub.status.busy":"2024-10-03T02:50:21.015246Z","iopub.execute_input":"2024-10-03T02:50:21.015710Z","iopub.status.idle":"2024-10-03T02:50:24.547341Z","shell.execute_reply.started":"2024-10-03T02:50:21.015665Z","shell.execute_reply":"2024-10-03T02:50:24.546326Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2024-10-03T02:50:31.032513Z","iopub.execute_input":"2024-10-03T02:50:31.032956Z","iopub.status.idle":"2024-10-03T02:50:31.062987Z","shell.execute_reply.started":"2024-10-03T02:50:31.032916Z","shell.execute_reply":"2024-10-03T02:50:31.061954Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x = df.iloc[:,1:]\ny = df.iloc[:,0]","metadata":{"execution":{"iopub.status.busy":"2024-10-03T02:54:57.735923Z","iopub.execute_input":"2024-10-03T02:54:57.736898Z","iopub.status.idle":"2024-10-03T02:54:57.742245Z","shell.execute_reply.started":"2024-10-03T02:54:57.736853Z","shell.execute_reply":"2024-10-03T02:54:57.741031Z"},"trusted":true},"execution_count":null,"outputs":[]},{"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.2,random_state=42)","metadata":{"execution":{"iopub.status.busy":"2024-10-03T02:58:21.245860Z","iopub.execute_input":"2024-10-03T02:58:21.246884Z","iopub.status.idle":"2024-10-03T02:58:21.495578Z","shell.execute_reply.started":"2024-10-03T02:58:21.246823Z","shell.execute_reply":"2024-10-03T02:58:21.494289Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.preprocessing import StandardScaler\nscaler=StandardScaler()","metadata":{"execution":{"iopub.status.busy":"2024-10-03T03:04:15.893135Z","iopub.execute_input":"2024-10-03T03:04:15.893564Z","iopub.status.idle":"2024-10-03T03:04:15.898660Z","shell.execute_reply.started":"2024-10-03T03:04:15.893525Z","shell.execute_reply":"2024-10-03T03:04:15.897578Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_train=scaler.fit_transform(x_train)\nx_test = scaler.transform(x_test)","metadata":{"execution":{"iopub.status.busy":"2024-10-03T03:04:20.114011Z","iopub.execute_input":"2024-10-03T03:04:20.114523Z","iopub.status.idle":"2024-10-03T03:04:20.653989Z","shell.execute_reply.started":"2024-10-03T03:04:20.114474Z","shell.execute_reply":"2024-10-03T03:04:20.652724Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.decomposition import PCA\npca = PCA(n_components=100)","metadata":{"execution":{"iopub.status.busy":"2024-10-03T03:08:09.621013Z","iopub.execute_input":"2024-10-03T03:08:09.621444Z","iopub.status.idle":"2024-10-03T03:08:09.627032Z","shell.execute_reply.started":"2024-10-03T03:08:09.621407Z","shell.execute_reply":"2024-10-03T03:08:09.625833Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_train = pca.fit_transform(x_train)\nx_test = pca.transform(x_test)","metadata":{"execution":{"iopub.status.busy":"2024-10-03T03:08:12.031363Z","iopub.execute_input":"2024-10-03T03:08:12.031812Z","iopub.status.idle":"2024-10-03T03:08:15.849069Z","shell.execute_reply.started":"2024-10-03T03:08:12.031772Z","shell.execute_reply":"2024-10-03T03:08:15.847672Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_train.shape","metadata":{"execution":{"iopub.status.busy":"2024-10-03T03:08:26.439407Z","iopub.execute_input":"2024-10-03T03:08:26.439843Z","iopub.status.idle":"2024-10-03T03:08:26.448682Z","shell.execute_reply.started":"2024-10-03T03:08:26.439799Z","shell.execute_reply":"2024-10-03T03:08:26.447469Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.neighbors import KNeighborsClassifier","metadata":{"execution":{"iopub.status.busy":"2024-10-03T03:12:55.117786Z","iopub.execute_input":"2024-10-03T03:12:55.118713Z","iopub.status.idle":"2024-10-03T03:12:55.159518Z","shell.execute_reply.started":"2024-10-03T03:12:55.118662Z","shell.execute_reply":"2024-10-03T03:12:55.158410Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"knn = KNeighborsClassifier()","metadata":{"execution":{"iopub.status.busy":"2024-10-03T03:12:58.288355Z","iopub.execute_input":"2024-10-03T03:12:58.288789Z","iopub.status.idle":"2024-10-03T03:12:58.293849Z","shell.execute_reply.started":"2024-10-03T03:12:58.288726Z","shell.execute_reply":"2024-10-03T03:12:58.292427Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"knn.fit(x_train,y_train)","metadata":{"execution":{"iopub.status.busy":"2024-10-03T03:13:53.514775Z","iopub.execute_input":"2024-10-03T03:13:53.515227Z","iopub.status.idle":"2024-10-03T03:13:53.540274Z","shell.execute_reply.started":"2024-10-03T03:13:53.515185Z","shell.execute_reply":"2024-10-03T03:13:53.539175Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred=knn.predict(x_test)\n","metadata":{"execution":{"iopub.status.busy":"2024-10-03T03:15:00.847428Z","iopub.execute_input":"2024-10-03T03:15:00.847900Z","iopub.status.idle":"2024-10-03T03:15:02.580681Z","shell.execute_reply.started":"2024-10-03T03:15:00.847860Z","shell.execute_reply":"2024-10-03T03:15:02.579397Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.metrics import accuracy_score\naccuracy_score(y_test,y_pred)","metadata":{"execution":{"iopub.status.busy":"2024-10-03T03:17:31.223665Z","iopub.execute_input":"2024-10-03T03:17:31.224102Z","iopub.status.idle":"2024-10-03T03:17:31.233977Z","shell.execute_reply.started":"2024-10-03T03:17:31.224064Z","shell.execute_reply":"2024-10-03T03:17:31.232845Z"},"trusted":true},"execution_count":null,"outputs":[]}]}