{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.13","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":30698,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nfrom sklearn.linear_model import LogisticRegression\n\n%matplotlib inline","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2024-05-13T03:17:55.304629Z","iopub.execute_input":"2024-05-13T03:17:55.305031Z","iopub.status.idle":"2024-05-13T03:17:55.312863Z","shell.execute_reply.started":"2024-05-13T03:17:55.304997Z","shell.execute_reply":"2024-05-13T03:17:55.311116Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df = pd.read_csv(\"../input/digit-recognizer/train.csv\")\nx_train = train_df.iloc[:, 1:].values\ny_train = train_df.iloc[:, 0].values","metadata":{"execution":{"iopub.status.busy":"2024-05-13T03:14:18.980053Z","iopub.execute_input":"2024-05-13T03:14:18.980464Z","iopub.status.idle":"2024-05-13T03:14:23.162161Z","shell.execute_reply.started":"2024-05-13T03:14:18.980429Z","shell.execute_reply":"2024-05-13T03:14:23.160948Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 何をやっているかの参考用\nindex_to_show = 0\nplt.imshow(x_train[index_to_show].reshape((28, 28)))\nplt.show()\nprint(y_train[index_to_show])","metadata":{"execution":{"iopub.status.busy":"2024-05-13T03:18:52.769146Z","iopub.execute_input":"2024-05-13T03:18:52.769586Z","iopub.status.idle":"2024-05-13T03:18:53.016959Z","shell.execute_reply.started":"2024-05-13T03:18:52.769552Z","shell.execute_reply":"2024-05-13T03:18:53.015715Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = LogisticRegression()\nmodel.fit(x_train, y_train)","metadata":{"execution":{"iopub.status.busy":"2024-05-13T03:15:47.365459Z","iopub.execute_input":"2024-05-13T03:15:47.365858Z","iopub.status.idle":"2024-05-13T03:16:01.234903Z","shell.execute_reply.started":"2024-05-13T03:15:47.365829Z","shell.execute_reply":"2024-05-13T03:16:01.233663Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred = model.predict(x_train)","metadata":{"execution":{"iopub.status.busy":"2024-05-13T03:16:26.741653Z","iopub.execute_input":"2024-05-13T03:16:26.742601Z","iopub.status.idle":"2024-05-13T03:16:26.920003Z","shell.execute_reply.started":"2024-05-13T03:16:26.742559Z","shell.execute_reply":"2024-05-13T03:16:26.918439Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 行が予測、列が実際\n# 本当は過学習しているかもしれないが、簡単のためここでは良いことにする\npd.crosstab(y_pred, y_train)","metadata":{"execution":{"iopub.status.busy":"2024-05-13T03:22:51.437742Z","iopub.execute_input":"2024-05-13T03:22:51.438195Z","iopub.status.idle":"2024-05-13T03:22:51.469049Z","shell.execute_reply.started":"2024-05-13T03:22:51.438161Z","shell.execute_reply":"2024-05-13T03:22:51.467876Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}