{"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-24T14:41:04.766950Z","iopub.execute_input":"2022-03-24T14:41:04.767594Z","iopub.status.idle":"2022-03-24T14:41:04.795339Z","shell.execute_reply.started":"2022-03-24T14:41:04.767472Z","shell.execute_reply":"2022-03-24T14:41:04.794397Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"訓練データ取り出し","metadata":{}},{"cell_type":"code","source":"train = pd.read_csv('/kaggle/input/digit-recognizer/train.csv')\ntest = pd.read_csv('/kaggle/input/digit-recognizer/test.csv')","metadata":{"execution":{"iopub.status.busy":"2022-03-24T14:41:47.177969Z","iopub.execute_input":"2022-03-24T14:41:47.178278Z","iopub.status.idle":"2022-03-24T14:41:52.981291Z","shell.execute_reply.started":"2022-03-24T14:41:47.178246Z","shell.execute_reply":"2022-03-24T14:41:52.980094Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib as mpl\nimport matplotlib.pyplot as plt\n%matplotlib inline","metadata":{"execution":{"iopub.status.busy":"2022-03-24T14:41:52.983204Z","iopub.execute_input":"2022-03-24T14:41:52.983689Z","iopub.status.idle":"2022-03-24T14:41:52.992290Z","shell.execute_reply.started":"2022-03-24T14:41:52.983643Z","shell.execute_reply":"2022-03-24T14:41:52.991497Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_Y = train['label']\ntrain_X = train.drop('label', axis=1)","metadata":{"execution":{"iopub.status.busy":"2022-03-24T14:41:52.993681Z","iopub.execute_input":"2022-03-24T14:41:52.994240Z","iopub.status.idle":"2022-03-24T14:41:53.135083Z","shell.execute_reply.started":"2022-03-24T14:41:52.994196Z","shell.execute_reply":"2022-03-24T14:41:53.134169Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"データの観察","metadata":{"execution":{"iopub.status.busy":"2022-03-24T11:12:05.331239Z","iopub.execute_input":"2022-03-24T11:12:05.331571Z","iopub.status.idle":"2022-03-24T11:12:05.448296Z","shell.execute_reply.started":"2022-03-24T11:12:05.331539Z","shell.execute_reply":"2022-03-24T11:12:05.447279Z"}}},{"cell_type":"code","source":"train_X.describe()","metadata":{"execution":{"iopub.status.busy":"2022-03-24T14:41:55.795830Z","iopub.execute_input":"2022-03-24T14:41:55.796119Z","iopub.status.idle":"2022-03-24T14:41:58.013112Z","shell.execute_reply.started":"2022-03-24T14:41:55.796091Z","shell.execute_reply":"2022-03-24T14:41:58.012243Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"first_element = train_X.loc[0].values\nfirst_element_image = first_element.reshape(28, 28)\nplt.imshow(first_element_image, cmap=\"binary\")\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-24T14:42:04.100579Z","iopub.execute_input":"2022-03-24T14:42:04.101162Z","iopub.status.idle":"2022-03-24T14:42:04.262434Z","shell.execute_reply.started":"2022-03-24T14:42:04.101122Z","shell.execute_reply":"2022-03-24T14:42:04.261440Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import cross_val_score","metadata":{"execution":{"iopub.status.busy":"2022-03-24T14:42:18.136053Z","iopub.execute_input":"2022-03-24T14:42:18.136326Z","iopub.status.idle":"2022-03-24T14:42:19.066381Z","shell.execute_reply.started":"2022-03-24T14:42:18.136298Z","shell.execute_reply":"2022-03-24T14:42:19.065453Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.preprocessing import MinMaxScaler","metadata":{"execution":{"iopub.status.busy":"2022-03-24T14:42:23.078358Z","iopub.execute_input":"2022-03-24T14:42:23.078660Z","iopub.status.idle":"2022-03-24T14:42:23.082488Z","shell.execute_reply.started":"2022-03-24T14:42:23.078626Z","shell.execute_reply":"2022-03-24T14:42:23.081879Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.svm import SVC\nfrom sklearn.pipeline import make_pipeline\n\nsvm_clf = make_pipeline(MinMaxScaler(), SVC())\nsvm_clf.fit(train_X, train_Y)","metadata":{"execution":{"iopub.status.busy":"2022-03-24T14:42:35.288530Z","iopub.execute_input":"2022-03-24T14:42:35.288984Z","iopub.status.idle":"2022-03-24T14:45:12.493723Z","shell.execute_reply.started":"2022-03-24T14:42:35.288947Z","shell.execute_reply":"2022-03-24T14:45:12.492939Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pre = svm_clf.predict(test)","metadata":{"execution":{"iopub.status.busy":"2022-03-24T14:45:12.495291Z","iopub.execute_input":"2022-03-24T14:45:12.495508Z","iopub.status.idle":"2022-03-24T14:49:13.344319Z","shell.execute_reply.started":"2022-03-24T14:45:12.495480Z","shell.execute_reply":"2022-03-24T14:49:13.343534Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"index = np.array(range(1, 28001))","metadata":{"execution":{"iopub.status.busy":"2022-03-24T14:49:33.053669Z","iopub.execute_input":"2022-03-24T14:49:33.053986Z","iopub.status.idle":"2022-03-24T14:49:33.063065Z","shell.execute_reply.started":"2022-03-24T14:49:33.053938Z","shell.execute_reply":"2022-03-24T14:49:33.062183Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_sub = pd.DataFrame({'ImageId': index, \n                       'Label': pre})","metadata":{"execution":{"iopub.status.busy":"2022-03-24T15:02:52.562505Z","iopub.execute_input":"2022-03-24T15:02:52.563136Z","iopub.status.idle":"2022-03-24T15:02:52.567533Z","shell.execute_reply.started":"2022-03-24T15:02:52.563083Z","shell.execute_reply":"2022-03-24T15:02:52.566932Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_sub","metadata":{"execution":{"iopub.status.busy":"2022-03-24T15:02:55.483691Z","iopub.execute_input":"2022-03-24T15:02:55.484104Z","iopub.status.idle":"2022-03-24T15:02:55.493827Z","shell.execute_reply.started":"2022-03-24T15:02:55.484073Z","shell.execute_reply":"2022-03-24T15:02:55.492935Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_sub.to_csv('submission.csv', index=False)","metadata":{"execution":{"iopub.status.busy":"2022-03-24T15:02:58.461451Z","iopub.execute_input":"2022-03-24T15:02:58.462342Z","iopub.status.idle":"2022-03-24T15:02:58.512914Z","shell.execute_reply.started":"2022-03-24T15:02:58.462279Z","shell.execute_reply":"2022-03-24T15:02:58.512265Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"kakunin = pd.read_csv('submission.csv')\nkakunin","metadata":{"execution":{"iopub.status.busy":"2022-03-24T15:03:05.260265Z","iopub.execute_input":"2022-03-24T15:03:05.260690Z","iopub.status.idle":"2022-03-24T15:03:05.277640Z","shell.execute_reply.started":"2022-03-24T15:03:05.260659Z","shell.execute_reply":"2022-03-24T15:03:05.277001Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_sub.to_csv('submission.csv', index = False)","metadata":{"execution":{"iopub.status.busy":"2022-03-24T14:50:31.757744Z","iopub.execute_input":"2022-03-24T14:50:31.758255Z","iopub.status.idle":"2022-03-24T14:50:31.811357Z","shell.execute_reply.started":"2022-03-24T14:50:31.758211Z","shell.execute_reply":"2022-03-24T14:50:31.810758Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}