{"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","trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd\ntrain_data=pd.read_csv('/kaggle/input/digit-recognizer/train.csv')\n\n","metadata":{"execution":{"iopub.status.busy":"2023-01-24T04:36:05.289775Z","iopub.execute_input":"2023-01-24T04:36:05.290089Z","iopub.status.idle":"2023-01-24T04:36:08.065298Z","shell.execute_reply.started":"2023-01-24T04:36:05.290063Z","shell.execute_reply":"2023-01-24T04:36:08.063507Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data.head()","metadata":{"execution":{"iopub.status.busy":"2023-01-24T04:36:36.852265Z","iopub.execute_input":"2023-01-24T04:36:36.85263Z","iopub.status.idle":"2023-01-24T04:36:36.883009Z","shell.execute_reply.started":"2023-01-24T04:36:36.852603Z","shell.execute_reply":"2023-01-24T04:36:36.881092Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data.shape","metadata":{"execution":{"iopub.status.busy":"2023-01-24T04:37:06.876542Z","iopub.execute_input":"2023-01-24T04:37:06.876886Z","iopub.status.idle":"2023-01-24T04:37:06.88557Z","shell.execute_reply.started":"2023-01-24T04:37:06.876859Z","shell.execute_reply":"2023-01-24T04:37:06.884377Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x=train_data.drop('label',axis=1)\ny=train_data['label']\nprint(x[:10])\nprint(y[:10])","metadata":{"execution":{"iopub.status.busy":"2023-01-24T04:37:33.92329Z","iopub.execute_input":"2023-01-24T04:37:33.923641Z","iopub.status.idle":"2023-01-24T04:37:34.007381Z","shell.execute_reply.started":"2023-01-24T04:37:33.923613Z","shell.execute_reply":"2023-01-24T04:37:34.005621Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nimport numpy as np\nplt.figure(figsize=(7,7))\nsome_digit=120\nsome_digit_image=x.iloc[some_digit].to_numpy().reshape(28,28)\nplt.imshow(np.reshape(some_digit_image,(28,28)),cmap=plt.cm.gray)\nprint(y[some_digit])\n","metadata":{"execution":{"iopub.status.busy":"2023-01-24T04:37:58.476783Z","iopub.execute_input":"2023-01-24T04:37:58.477237Z","iopub.status.idle":"2023-01-24T04:37:58.640312Z","shell.execute_reply.started":"2023-01-24T04:37:58.477183Z","shell.execute_reply":"2023-01-24T04:37:58.639634Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nimport numpy as np\nplt.figure(figsize=(7,7))\nsome_digit=523\nsome_digit_image=x.iloc[some_digit].to_numpy().reshape(28,28)\nplt.imshow(np.reshape(some_digit_image,(28,28)),cmap=plt.cm.gray)\nprint(y[some_digit])","metadata":{"execution":{"iopub.status.busy":"2023-01-24T04:38:26.97681Z","iopub.execute_input":"2023-01-24T04:38:26.977586Z","iopub.status.idle":"2023-01-24T04:38:27.112437Z","shell.execute_reply.started":"2023-01-24T04:38:26.977556Z","shell.execute_reply":"2023-01-24T04:38:27.111501Z"},"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)\nprint(x_train.shape)\nprint(x_test.shape)\nprint(y_train.shape)\nprint(y_test.shape)","metadata":{"execution":{"iopub.status.busy":"2023-01-24T04:38:52.156678Z","iopub.execute_input":"2023-01-24T04:38:52.157243Z","iopub.status.idle":"2023-01-24T04:38:53.309604Z","shell.execute_reply.started":"2023-01-24T04:38:52.157212Z","shell.execute_reply":"2023-01-24T04:38:53.3087Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.linear_model import LogisticRegression\nlr=LogisticRegression(random_state=1000)\nlr.fit(x_train,y_train)","metadata":{"execution":{"iopub.status.busy":"2023-01-24T04:39:14.706911Z","iopub.execute_input":"2023-01-24T04:39:14.70725Z","iopub.status.idle":"2023-01-24T04:39:25.376502Z","shell.execute_reply.started":"2023-01-24T04:39:14.707222Z","shell.execute_reply":"2023-01-24T04:39:25.375814Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred=lr.predict(x_test)\ny_pred","metadata":{"execution":{"iopub.status.busy":"2023-01-24T04:39:51.049074Z","iopub.execute_input":"2023-01-24T04:39:51.049453Z","iopub.status.idle":"2023-01-24T04:39:51.095145Z","shell.execute_reply.started":"2023-01-24T04:39:51.049424Z","shell.execute_reply":"2023-01-24T04:39:51.094361Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.metrics import accuracy_score\nprint(accuracy_score(y_test, y_pred))","metadata":{"execution":{"iopub.status.busy":"2023-01-24T04:40:12.632231Z","iopub.execute_input":"2023-01-24T04:40:12.632639Z","iopub.status.idle":"2023-01-24T04:40:12.639013Z","shell.execute_reply.started":"2023-01-24T04:40:12.632609Z","shell.execute_reply":"2023-01-24T04:40:12.638072Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import seaborn as sns\nsns.regplot(x=y,y=y_pred,data=df,logistic=True)","metadata":{"execution":{"iopub.status.busy":"2023-01-24T04:40:58.636406Z","iopub.execute_input":"2023-01-24T04:40:58.636754Z","iopub.status.idle":"2023-01-24T04:40:58.84576Z","shell.execute_reply.started":"2023-01-24T04:40:58.636726Z","shell.execute_reply":"2023-01-24T04:40:58.844332Z"},"trusted":true},"execution_count":null,"outputs":[]}]}