{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.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":30587,"isInternetEnabled":true,"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":"2023-11-25T08:50:12.639953Z","iopub.execute_input":"2023-11-25T08:50:12.640447Z","iopub.status.idle":"2023-11-25T08:50:13.105734Z","shell.execute_reply.started":"2023-11-25T08:50:12.640407Z","shell.execute_reply":"2023-11-25T08:50:13.104361Z"},"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":"2023-11-25T08:50:13.364634Z","iopub.execute_input":"2023-11-25T08:50:13.365219Z","iopub.status.idle":"2023-11-25T08:50:17.637939Z","shell.execute_reply.started":"2023-11-25T08:50:13.365181Z","shell.execute_reply":"2023-11-25T08:50:17.636897Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2023-11-25T08:50:22.11029Z","iopub.execute_input":"2023-11-25T08:50:22.111081Z","iopub.status.idle":"2023-11-25T08:50:22.142627Z","shell.execute_reply.started":"2023-11-25T08:50:22.111029Z","shell.execute_reply":"2023-11-25T08:50:22.141231Z"},"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(df.iloc[:,1:],df.iloc[:,0],test_size=0.2,random_state=2)","metadata":{"execution":{"iopub.status.busy":"2023-11-25T08:52:22.529057Z","iopub.execute_input":"2023-11-25T08:52:22.529528Z","iopub.status.idle":"2023-11-25T08:52:22.796666Z","shell.execute_reply.started":"2023-11-25T08:52:22.529491Z","shell.execute_reply":"2023-11-25T08:52:22.795432Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.linear_model import LogisticRegression\nfrom sklearn.tree import DecisionTreeClassifier","metadata":{"execution":{"iopub.status.busy":"2023-11-25T08:54:00.522948Z","iopub.execute_input":"2023-11-25T08:54:00.523423Z","iopub.status.idle":"2023-11-25T08:54:00.726109Z","shell.execute_reply.started":"2023-11-25T08:54:00.523386Z","shell.execute_reply":"2023-11-25T08:54:00.724782Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"clf1=LogisticRegression()\nclf2=DecisionTreeClassifier()","metadata":{"execution":{"iopub.status.busy":"2023-11-25T08:54:45.130736Z","iopub.execute_input":"2023-11-25T08:54:45.13117Z","iopub.status.idle":"2023-11-25T08:54:45.137008Z","shell.execute_reply.started":"2023-11-25T08:54:45.131137Z","shell.execute_reply":"2023-11-25T08:54:45.135778Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"clf1.fit(x_train,y_train)","metadata":{"execution":{"iopub.status.busy":"2023-11-25T08:54:58.84089Z","iopub.execute_input":"2023-11-25T08:54:58.841434Z","iopub.status.idle":"2023-11-25T08:55:18.338829Z","shell.execute_reply.started":"2023-11-25T08:54:58.841393Z","shell.execute_reply":"2023-11-25T08:55:18.337611Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"clf2.fit(x_train,y_train)","metadata":{"execution":{"iopub.status.busy":"2023-11-25T08:55:18.421162Z","iopub.execute_input":"2023-11-25T08:55:18.422078Z","iopub.status.idle":"2023-11-25T08:55:29.774607Z","shell.execute_reply.started":"2023-11-25T08:55:18.422031Z","shell.execute_reply":"2023-11-25T08:55:29.773387Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred1=clf1.predict(x_test)\ny_pred2=clf2.predict(x_test)","metadata":{"execution":{"iopub.status.busy":"2023-11-25T08:55:52.558617Z","iopub.execute_input":"2023-11-25T08:55:52.55903Z","iopub.status.idle":"2023-11-25T08:55:52.686179Z","shell.execute_reply.started":"2023-11-25T08:55:52.558998Z","shell.execute_reply":"2023-11-25T08:55:52.68442Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.metrics import accuracy_score,confusion_matrix\nprint(\"Accuracy of Logistic Regression\",accuracy_score(y_test,y_pred1))\nprint(\"Accuracy of Decision Trees\",accuracy_score(y_test,y_pred2))","metadata":{"execution":{"iopub.status.busy":"2023-11-25T08:57:57.264361Z","iopub.execute_input":"2023-11-25T08:57:57.264864Z","iopub.status.idle":"2023-11-25T08:57:57.277077Z","shell.execute_reply.started":"2023-11-25T08:57:57.26482Z","shell.execute_reply":"2023-11-25T08:57:57.275441Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"LogRes Confusion Matrix\\n\")\npd.DataFrame(confusion_matrix(y_test,y_pred1), columns=list(range(0,10)))","metadata":{"execution":{"iopub.status.busy":"2023-11-25T08:59:06.067406Z","iopub.execute_input":"2023-11-25T08:59:06.067902Z","iopub.status.idle":"2023-11-25T08:59:06.094796Z","shell.execute_reply.started":"2023-11-25T08:59:06.067864Z","shell.execute_reply":"2023-11-25T08:59:06.093392Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"D Tree Confusion Matrix\\n\")\npd.DataFrame(confusion_matrix(y_test,y_pred2), columns=list(range(0,10)))","metadata":{"execution":{"iopub.status.busy":"2023-11-25T08:59:29.819626Z","iopub.execute_input":"2023-11-25T08:59:29.820044Z","iopub.status.idle":"2023-11-25T08:59:29.842422Z","shell.execute_reply.started":"2023-11-25T08:59:29.820012Z","shell.execute_reply":"2023-11-25T08:59:29.841334Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.metrics import precision_score, recall_score,f1_score","metadata":{"execution":{"iopub.status.busy":"2023-11-25T08:59:59.962117Z","iopub.execute_input":"2023-11-25T08:59:59.962635Z","iopub.status.idle":"2023-11-25T08:59:59.969014Z","shell.execute_reply.started":"2023-11-25T08:59:59.962589Z","shell.execute_reply":"2023-11-25T08:59:59.967594Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"precision_score(y_test,y_pred1,average='weighted')","metadata":{"execution":{"iopub.status.busy":"2023-11-25T09:00:24.769427Z","iopub.execute_input":"2023-11-25T09:00:24.769929Z","iopub.status.idle":"2023-11-25T09:00:24.786984Z","shell.execute_reply.started":"2023-11-25T09:00:24.769889Z","shell.execute_reply":"2023-11-25T09:00:24.785479Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"recall_score(y_test,y_pred1,average='weighted')","metadata":{"execution":{"iopub.status.busy":"2023-11-25T09:01:02.338464Z","iopub.execute_input":"2023-11-25T09:01:02.338888Z","iopub.status.idle":"2023-11-25T09:01:02.355882Z","shell.execute_reply.started":"2023-11-25T09:01:02.338849Z","shell.execute_reply":"2023-11-25T09:01:02.354426Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"f1_score(y_test,y_pred1,average='weighted')","metadata":{"execution":{"iopub.status.busy":"2023-11-25T09:01:26.606132Z","iopub.execute_input":"2023-11-25T09:01:26.606557Z","iopub.status.idle":"2023-11-25T09:01:26.621828Z","shell.execute_reply.started":"2023-11-25T09:01:26.606525Z","shell.execute_reply":"2023-11-25T09:01:26.620864Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.metrics import classification_report\nprint(classification_report(y_test,y_pred1))","metadata":{"execution":{"iopub.status.busy":"2023-11-25T09:02:09.770444Z","iopub.execute_input":"2023-11-25T09:02:09.770976Z","iopub.status.idle":"2023-11-25T09:02:09.80831Z","shell.execute_reply.started":"2023-11-25T09:02:09.770936Z","shell.execute_reply":"2023-11-25T09:02:09.806774Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}