{"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":"2022-03-03T04:08:33.4289Z","iopub.execute_input":"2022-03-03T04:08:33.429415Z","iopub.status.idle":"2022-03-03T04:08:33.438256Z","shell.execute_reply.started":"2022-03-03T04:08:33.429377Z","shell.execute_reply":"2022-03-03T04:08:33.437044Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Loading the dataset\ntrain = pd.read_csv('../input/digit-recognizer/train.csv')\ntest = pd.read_csv('../input/digit-recognizer/test.csv')","metadata":{"execution":{"iopub.status.busy":"2022-03-03T04:08:33.446353Z","iopub.execute_input":"2022-03-03T04:08:33.447186Z","iopub.status.idle":"2022-03-03T04:08:39.710373Z","shell.execute_reply.started":"2022-03-03T04:08:33.44713Z","shell.execute_reply":"2022-03-03T04:08:39.70972Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test.shape,train.shape","metadata":{"execution":{"iopub.status.busy":"2022-03-03T04:20:40.808868Z","iopub.execute_input":"2022-03-03T04:20:40.80953Z","iopub.status.idle":"2022-03-03T04:20:40.818259Z","shell.execute_reply.started":"2022-03-03T04:20:40.809483Z","shell.execute_reply":"2022-03-03T04:20:40.817536Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":" \nfrom sklearn.model_selection import train_test_split\n #apply algorithm on digit classification\nfrom sklearn.linear_model import LogisticRegression\n \nfrom sklearn.metrics import classification_report,confusion_matrix,accuracy_score\n\n","metadata":{"execution":{"iopub.status.busy":"2022-03-03T04:08:39.712091Z","iopub.execute_input":"2022-03-03T04:08:39.713106Z","iopub.status.idle":"2022-03-03T04:08:40.955193Z","shell.execute_reply.started":"2022-03-03T04:08:39.713057Z","shell.execute_reply":"2022-03-03T04:08:40.954038Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train,X_test,y_train,y_test=train_test_split(train.iloc[:,1:],train.iloc[:,:1],test_size=0.2,random_state=0)","metadata":{"execution":{"iopub.status.busy":"2022-03-03T04:08:40.956716Z","iopub.execute_input":"2022-03-03T04:08:40.956977Z","iopub.status.idle":"2022-03-03T04:08:41.227979Z","shell.execute_reply.started":"2022-03-03T04:08:40.956946Z","shell.execute_reply":"2022-03-03T04:08:41.226692Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"log=LogisticRegression()\nlog.fit(X_train,y_train)","metadata":{"execution":{"iopub.status.busy":"2022-03-03T04:08:41.230638Z","iopub.execute_input":"2022-03-03T04:08:41.231089Z","iopub.status.idle":"2022-03-03T04:09:00.701194Z","shell.execute_reply.started":"2022-03-03T04:08:41.231039Z","shell.execute_reply":"2022-03-03T04:09:00.70023Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred_log=log.predict(X_test)\nprint(accuracy_score(y_test,y_pred_log))","metadata":{"execution":{"iopub.status.busy":"2022-03-03T04:09:00.707024Z","iopub.execute_input":"2022-03-03T04:09:00.709824Z","iopub.status.idle":"2022-03-03T04:09:00.824861Z","shell.execute_reply.started":"2022-03-03T04:09:00.709758Z","shell.execute_reply":"2022-03-03T04:09:00.823743Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(classification_report(y_test,y_pred_log))","metadata":{"execution":{"iopub.status.busy":"2022-03-03T04:09:00.832245Z","iopub.execute_input":"2022-03-03T04:09:00.835485Z","iopub.status.idle":"2022-03-03T04:09:00.885587Z","shell.execute_reply.started":"2022-03-03T04:09:00.835418Z","shell.execute_reply":"2022-03-03T04:09:00.884618Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"raw","source":"prediction=log.predict(X_test)\n","metadata":{"execution":{"iopub.status.busy":"2022-03-03T04:18:13.816867Z","iopub.execute_input":"2022-03-03T04:18:13.817122Z","iopub.status.idle":"2022-03-03T04:18:13.840946Z","shell.execute_reply.started":"2022-03-03T04:18:13.817095Z","shell.execute_reply":"2022-03-03T04:18:13.8396Z"}}},{"cell_type":"code","source":"test_chek=test.iloc[:,:]","metadata":{"execution":{"iopub.status.busy":"2022-03-03T04:21:46.298461Z","iopub.execute_input":"2022-03-03T04:21:46.298833Z","iopub.status.idle":"2022-03-03T04:21:46.303378Z","shell.execute_reply.started":"2022-03-03T04:21:46.298796Z","shell.execute_reply":"2022-03-03T04:21:46.302476Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"prediction=log.predict(test_chek)\nlen(prediction)","metadata":{"execution":{"iopub.status.busy":"2022-03-03T04:21:53.643589Z","iopub.execute_input":"2022-03-03T04:21:53.643971Z","iopub.status.idle":"2022-03-03T04:21:53.884921Z","shell.execute_reply.started":"2022-03-03T04:21:53.643932Z","shell.execute_reply":"2022-03-03T04:21:53.883314Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd \nsubmissions=pd.DataFrame({\"ImageId\": list(range(1,len(prediction)+1)),\"Label\": prediction})\nsubmissions.to_csv(\"submission.csv\", index=False, header=True)","metadata":{"execution":{"iopub.status.busy":"2022-03-03T04:22:00.398899Z","iopub.execute_input":"2022-03-03T04:22:00.399167Z","iopub.status.idle":"2022-03-03T04:22:00.46761Z","shell.execute_reply.started":"2022-03-03T04:22:00.399138Z","shell.execute_reply":"2022-03-03T04:22:00.466715Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.ensemble import RandomForestClassifier\n\nrf=RandomForestClassifier()\nrf.fit(X_train,y_train)\n","metadata":{"execution":{"iopub.status.busy":"2022-03-03T04:26:51.819967Z","iopub.execute_input":"2022-03-03T04:26:51.820309Z","iopub.status.idle":"2022-03-03T04:27:17.695861Z","shell.execute_reply.started":"2022-03-03T04:26:51.820277Z","shell.execute_reply":"2022-03-03T04:27:17.694793Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"prediction=rf.predict(test_chek)\nimport pandas as pd \nsubmissions=pd.DataFrame({\"ImageId\": list(range(1,len(prediction)+1)),\"Label\": prediction})\nsubmissions.to_csv(\"submission.csv\", index=False, header=True)\n\n","metadata":{"execution":{"iopub.status.busy":"2022-03-03T04:28:00.332154Z","iopub.execute_input":"2022-03-03T04:28:00.333177Z","iopub.status.idle":"2022-03-03T04:28:01.788919Z","shell.execute_reply.started":"2022-03-03T04:28:00.333125Z","shell.execute_reply":"2022-03-03T04:28:01.787973Z"},"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":[]}]}