{"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-10-25T13:24:49.801955Z","iopub.execute_input":"2023-10-25T13:24:49.802232Z","iopub.status.idle":"2023-10-25T13:24:50.184136Z","shell.execute_reply.started":"2023-10-25T13:24:49.802206Z","shell.execute_reply":"2023-10-25T13:24:50.183031Z"},"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-10-25T13:25:38.007919Z","iopub.execute_input":"2023-10-25T13:25:38.008275Z","iopub.status.idle":"2023-10-25T13:25:42.195448Z","shell.execute_reply.started":"2023-10-25T13:25:38.008247Z","shell.execute_reply":"2023-10-25T13:25:42.194353Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2023-10-25T13:25:51.228530Z","iopub.execute_input":"2023-10-25T13:25:51.228918Z","iopub.status.idle":"2023-10-25T13:25:51.256311Z","shell.execute_reply.started":"2023-10-25T13:25:51.228884Z","shell.execute_reply":"2023-10-25T13:25:51.255125Z"},"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-10-25T13:26:01.259637Z","iopub.execute_input":"2023-10-25T13:26:01.260593Z","iopub.status.idle":"2023-10-25T13:26:02.113238Z","shell.execute_reply.started":"2023-10-25T13:26:01.260559Z","shell.execute_reply":"2023-10-25T13:26:02.112254Z"},"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-10-25T13:26:23.512104Z","iopub.execute_input":"2023-10-25T13:26:23.512467Z","iopub.status.idle":"2023-10-25T13:26:23.734373Z","shell.execute_reply.started":"2023-10-25T13:26:23.512436Z","shell.execute_reply":"2023-10-25T13:26:23.733397Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"clf1 = LogisticRegression()\nclf2 = DecisionTreeClassifier()","metadata":{"execution":{"iopub.status.busy":"2023-10-25T13:26:32.297704Z","iopub.execute_input":"2023-10-25T13:26:32.298601Z","iopub.status.idle":"2023-10-25T13:26:32.303142Z","shell.execute_reply.started":"2023-10-25T13:26:32.298568Z","shell.execute_reply":"2023-10-25T13:26:32.301894Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"clf1.fit(X_train,y_train)\nclf2.fit(X_train,y_train)","metadata":{"execution":{"iopub.status.busy":"2023-10-25T13:26:41.158713Z","iopub.execute_input":"2023-10-25T13:26:41.159573Z","iopub.status.idle":"2023-10-25T13:27:06.902067Z","shell.execute_reply.started":"2023-10-25T13:26:41.159537Z","shell.execute_reply":"2023-10-25T13:27:06.901060Z"},"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-10-25T13:27:12.650682Z","iopub.execute_input":"2023-10-25T13:27:12.651329Z","iopub.status.idle":"2023-10-25T13:27:12.754339Z","shell.execute_reply.started":"2023-10-25T13:27:12.651292Z","shell.execute_reply":"2023-10-25T13:27:12.752875Z"},"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-10-25T13:27:19.250718Z","iopub.execute_input":"2023-10-25T13:27:19.251058Z","iopub.status.idle":"2023-10-25T13:27:19.259370Z","shell.execute_reply.started":"2023-10-25T13:27:19.251031Z","shell.execute_reply":"2023-10-25T13:27:19.258488Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"Logistic Regression Confusion Matrix\\n\")\npd.DataFrame(confusion_matrix(y_test,y_pred1),columns=list(range(0,10)))","metadata":{"execution":{"iopub.status.busy":"2023-10-25T13:27:33.377713Z","iopub.execute_input":"2023-10-25T13:27:33.378108Z","iopub.status.idle":"2023-10-25T13:27:33.399449Z","shell.execute_reply.started":"2023-10-25T13:27:33.378075Z","shell.execute_reply":"2023-10-25T13:27:33.398575Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"Decision Tree Confusion Matrix\\n\")\npd.DataFrame(confusion_matrix(y_test,y_pred2),columns=list(range(0,10)))","metadata":{"execution":{"iopub.status.busy":"2023-10-25T13:28:15.236478Z","iopub.execute_input":"2023-10-25T13:28:15.237261Z","iopub.status.idle":"2023-10-25T13:28:15.253809Z","shell.execute_reply.started":"2023-10-25T13:28:15.237222Z","shell.execute_reply":"2023-10-25T13:28:15.252920Z"},"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-10-25T13:28:48.227797Z","iopub.execute_input":"2023-10-25T13:28:48.228224Z","iopub.status.idle":"2023-10-25T13:28:48.232786Z","shell.execute_reply.started":"2023-10-25T13:28:48.228195Z","shell.execute_reply":"2023-10-25T13:28:48.231784Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"precision_score(y_test,y_pred1,average='weighted')","metadata":{"execution":{"iopub.status.busy":"2023-10-25T13:28:56.031415Z","iopub.execute_input":"2023-10-25T13:28:56.031785Z","iopub.status.idle":"2023-10-25T13:28:56.045107Z","shell.execute_reply.started":"2023-10-25T13:28:56.031756Z","shell.execute_reply":"2023-10-25T13:28:56.044241Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"f1_score(y_test,y_pred1,average='weighted')","metadata":{"execution":{"iopub.status.busy":"2023-10-25T13:29:07.837258Z","iopub.execute_input":"2023-10-25T13:29:07.837599Z","iopub.status.idle":"2023-10-25T13:29:07.851035Z","shell.execute_reply.started":"2023-10-25T13:29:07.837572Z","shell.execute_reply":"2023-10-25T13:29:07.850252Z"},"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-10-25T13:29:16.908626Z","iopub.execute_input":"2023-10-25T13:29:16.909650Z","iopub.status.idle":"2023-10-25T13:29:16.938383Z","shell.execute_reply.started":"2023-10-25T13:29:16.909614Z","shell.execute_reply":"2023-10-25T13:29:16.937357Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}