{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.12.12","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":31259,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport matplotlib.pyplot as plt\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.neighbors import KNeighborsClassifier\nfrom sklearn.metrics import accuracy_score","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2026-01-26T21:05:32.994759Z","iopub.execute_input":"2026-01-26T21:05:32.995498Z","iopub.status.idle":"2026-01-26T21:05:33.000404Z","shell.execute_reply.started":"2026-01-26T21:05:32.995462Z","shell.execute_reply":"2026-01-26T21:05:32.999222Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df = pd.read_csv('/kaggle/input/digit-recognizer/train.csv')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-01-26T21:05:33.002258Z","iopub.execute_input":"2026-01-26T21:05:33.002584Z","iopub.status.idle":"2026-01-26T21:05:35.458769Z","shell.execute_reply.started":"2026-01-26T21:05:33.002553Z","shell.execute_reply":"2026-01-26T21:05:35.457919Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df.describe()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-01-26T21:05:35.459907Z","iopub.execute_input":"2026-01-26T21:05:35.460179Z","iopub.status.idle":"2026-01-26T21:05:37.262422Z","shell.execute_reply.started":"2026-01-26T21:05:35.460154Z","shell.execute_reply":"2026-01-26T21:05:37.261592Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df.head(10)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-01-26T21:05:37.263570Z","iopub.execute_input":"2026-01-26T21:05:37.263912Z","iopub.status.idle":"2026-01-26T21:05:37.278743Z","shell.execute_reply.started":"2026-01-26T21:05:37.263884Z","shell.execute_reply":"2026-01-26T21:05:37.277942Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df.sample()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-01-26T21:05:37.280861Z","iopub.execute_input":"2026-01-26T21:05:37.281147Z","iopub.status.idle":"2026-01-26T21:05:37.304825Z","shell.execute_reply.started":"2026-01-26T21:05:37.281120Z","shell.execute_reply":"2026-01-26T21:05:37.303452Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-01-26T21:05:37.306608Z","iopub.execute_input":"2026-01-26T21:05:37.307185Z","iopub.status.idle":"2026-01-26T21:05:37.323521Z","shell.execute_reply.started":"2026-01-26T21:05:37.307150Z","shell.execute_reply":"2026-01-26T21:05:37.322732Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"plt.imshow(df.iloc[12542,1:].values.reshape(28,28))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-01-26T21:05:37.324994Z","iopub.execute_input":"2026-01-26T21:05:37.325275Z","iopub.status.idle":"2026-01-26T21:05:37.468795Z","shell.execute_reply.started":"2026-01-26T21:05:37.325249Z","shell.execute_reply":"2026-01-26T21:05:37.467660Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"X = df.iloc[:,1:]\ny = df.iloc[:,0]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-01-26T21:05:37.469843Z","iopub.execute_input":"2026-01-26T21:05:37.470079Z","iopub.status.idle":"2026-01-26T21:05:37.475125Z","shell.execute_reply.started":"2026-01-26T21:05:37.470057Z","shell.execute_reply":"2026-01-26T21:05:37.474348Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"X_train,X_test,y_train,y_test=train_test_split(X,y,test_size=0.3,random_state=42)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-01-26T21:05:37.476103Z","iopub.execute_input":"2026-01-26T21:05:37.476380Z","iopub.status.idle":"2026-01-26T21:05:37.714338Z","shell.execute_reply.started":"2026-01-26T21:05:37.476353Z","shell.execute_reply":"2026-01-26T21:05:37.713350Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"X_train.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-01-26T21:05:37.715349Z","iopub.execute_input":"2026-01-26T21:05:37.715620Z","iopub.status.idle":"2026-01-26T21:05:37.721750Z","shell.execute_reply.started":"2026-01-26T21:05:37.715595Z","shell.execute_reply":"2026-01-26T21:05:37.720561Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"knn= KNeighborsClassifier()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-01-26T21:05:37.723253Z","iopub.execute_input":"2026-01-26T21:05:37.723622Z","iopub.status.idle":"2026-01-26T21:05:37.739679Z","shell.execute_reply.started":"2026-01-26T21:05:37.723586Z","shell.execute_reply":"2026-01-26T21:05:37.738619Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"knn.fit(X_train,y_train)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-01-26T21:05:37.740845Z","iopub.execute_input":"2026-01-26T21:05:37.741226Z","iopub.status.idle":"2026-01-26T21:05:37.857506Z","shell.execute_reply.started":"2026-01-26T21:05:37.741187Z","shell.execute_reply":"2026-01-26T21:05:37.856648Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"y_pred = knn.predict(X_test)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-01-26T21:05:37.858854Z","iopub.execute_input":"2026-01-26T21:05:37.859299Z","iopub.status.idle":"2026-01-26T21:05:50.699763Z","shell.execute_reply.started":"2026-01-26T21:05:37.859260Z","shell.execute_reply":"2026-01-26T21:05:50.698825Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"accuracy_score(y_test,y_pred)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-01-26T21:05:50.702180Z","iopub.execute_input":"2026-01-26T21:05:50.702492Z","iopub.status.idle":"2026-01-26T21:05:50.710928Z","shell.execute_reply.started":"2026-01-26T21:05:50.702463Z","shell.execute_reply":"2026-01-26T21:05:50.710033Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"submission = pd.DataFrame({'ImageId': range(1,len(y_test)+1) ,'Label': y_pred })\nsubmission.to_csv(\"simplemnist_result.csv\",index=False)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-01-26T21:05:50.711906Z","iopub.execute_input":"2026-01-26T21:05:50.712185Z","iopub.status.idle":"2026-01-26T21:05:50.737392Z","shell.execute_reply.started":"2026-01-26T21:05:50.712157Z","shell.execute_reply":"2026-01-26T21:05:50.736508Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}