{"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":"import numpy as np\nimport pandas as pd\n\nfrom sklearn.svm import SVC\nfrom sklearn.model_selection import KFold, train_test_split\nfrom sklearn.metrics import roc_auc_score, log_loss","metadata":{"execution":{"iopub.status.busy":"2022-09-23T23:52:06.645456Z","iopub.execute_input":"2022-09-23T23:52:06.645984Z","iopub.status.idle":"2022-09-23T23:52:06.653327Z","shell.execute_reply.started":"2022-09-23T23:52:06.645940Z","shell.execute_reply":"2022-09-23T23:52:06.652377Z"},"trusted":true},"execution_count":null,"outputs":[]},{"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 zipfile\nfrom sklearn.model_selection import train_test_split, KFold\nfrom sklearn.metrics import log_loss, roc_auc_score\nfrom sklearn.linear_model import LogisticRegression\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\n\n# You can write up to 5GB 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-09-23T23:52:08.087488Z","iopub.execute_input":"2022-09-23T23:52:08.087890Z","iopub.status.idle":"2022-09-23T23:52:08.094440Z","shell.execute_reply.started":"2022-09-23T23:52:08.087859Z","shell.execute_reply":"2022-09-23T23:52:08.093257Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample_submission = pd.read_csv('/kaggle/input/dogs-vs-cats-redux-kernels-edition/sample_submission.csv')\nsample_submission.tail()","metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","execution":{"iopub.status.busy":"2022-09-23T23:52:13.322736Z","iopub.execute_input":"2022-09-23T23:52:13.323160Z","iopub.status.idle":"2022-09-23T23:52:13.358130Z","shell.execute_reply.started":"2022-09-23T23:52:13.323126Z","shell.execute_reply":"2022-09-23T23:52:13.357183Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample_submission.head()","metadata":{"execution":{"iopub.status.busy":"2022-09-23T23:52:15.341111Z","iopub.execute_input":"2022-09-23T23:52:15.341519Z","iopub.status.idle":"2022-09-23T23:52:15.352728Z","shell.execute_reply.started":"2022-09-23T23:52:15.341484Z","shell.execute_reply":"2022-09-23T23:52:15.351661Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"TRAIN_FOLDER = '../input/cats-and-dogs-embedded-data/train/train/'\nTEST_FOLDER =  '../input/cats-and-dogs-embedded-data/test/test/'\nIMG_SIZE = 384","metadata":{"execution":{"iopub.status.busy":"2022-09-23T23:52:22.050069Z","iopub.execute_input":"2022-09-23T23:52:22.050515Z","iopub.status.idle":"2022-09-23T23:52:22.057209Z","shell.execute_reply.started":"2022-09-23T23:52:22.050481Z","shell.execute_reply":"2022-09-23T23:52:22.055670Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_image_list = np.load('../input/cats-and-dogs-embedded-data/cats_and_dogs_1/train_image_list.npy')\ntest_image_list = np.load('../input/cats-and-dogs-embedded-data/cats_and_dogs_1/test_image_list.npy')","metadata":{"execution":{"iopub.status.busy":"2022-09-23T23:52:29.775289Z","iopub.execute_input":"2022-09-23T23:52:29.775702Z","iopub.status.idle":"2022-09-23T23:52:29.803699Z","shell.execute_reply.started":"2022-09-23T23:52:29.775660Z","shell.execute_reply":"2022-09-23T23:52:29.802153Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_image_list","metadata":{"execution":{"iopub.status.busy":"2022-09-23T23:52:31.154599Z","iopub.execute_input":"2022-09-23T23:52:31.154993Z","iopub.status.idle":"2022-09-23T23:52:31.162368Z","shell.execute_reply.started":"2022-09-23T23:52:31.154961Z","shell.execute_reply":"2022-09-23T23:52:31.161173Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_image_list","metadata":{"execution":{"iopub.status.busy":"2022-09-23T23:52:32.262426Z","iopub.execute_input":"2022-09-23T23:52:32.262842Z","iopub.status.idle":"2022-09-23T23:52:32.270239Z","shell.execute_reply.started":"2022-09-23T23:52:32.262807Z","shell.execute_reply":"2022-09-23T23:52:32.269007Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ids = [int(x.split('.')[0]) for x in test_image_list]\nids[:20]","metadata":{"execution":{"iopub.status.busy":"2022-09-23T23:52:34.255667Z","iopub.execute_input":"2022-09-23T23:52:34.256102Z","iopub.status.idle":"2022-09-23T23:52:34.276389Z","shell.execute_reply.started":"2022-09-23T23:52:34.256066Z","shell.execute_reply":"2022-09-23T23:52:34.274846Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"target = np.load('../input/cats-and-dogs-embedded-data/cats_and_dogs_1/target.npy')","metadata":{"execution":{"iopub.status.busy":"2022-09-23T23:52:36.063460Z","iopub.execute_input":"2022-09-23T23:52:36.063853Z","iopub.status.idle":"2022-09-23T23:52:36.078518Z","shell.execute_reply.started":"2022-09-23T23:52:36.063824Z","shell.execute_reply":"2022-09-23T23:52:36.077488Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"target","metadata":{"execution":{"iopub.status.busy":"2022-09-23T23:52:41.779510Z","iopub.execute_input":"2022-09-23T23:52:41.780273Z","iopub.status.idle":"2022-09-23T23:52:41.787201Z","shell.execute_reply.started":"2022-09-23T23:52:41.780233Z","shell.execute_reply":"2022-09-23T23:52:41.785993Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_ENV2S = np.load('../input/cats-and-dogs-embedded-data/cats_and_dogs_5/cats_and_dogs_5/train_ENV2S.npy')\ntest_ENV2S = np.load('../input/cats-and-dogs-embedded-data/cats_and_dogs_5/cats_and_dogs_5/test_ENV2S.npy')","metadata":{"execution":{"iopub.status.busy":"2022-09-24T00:00:28.982630Z","iopub.execute_input":"2022-09-24T00:00:28.983130Z","iopub.status.idle":"2022-09-24T00:00:29.080116Z","shell.execute_reply.started":"2022-09-24T00:00:28.983089Z","shell.execute_reply":"2022-09-24T00:00:29.079026Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_ENV2S.shape","metadata":{"execution":{"iopub.status.busy":"2022-09-24T00:00:38.149159Z","iopub.execute_input":"2022-09-24T00:00:38.149567Z","iopub.status.idle":"2022-09-24T00:00:38.157798Z","shell.execute_reply.started":"2022-09-24T00:00:38.149534Z","shell.execute_reply":"2022-09-24T00:00:38.156269Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train, X_val, y_train, y_val = train_test_split(train_ENV2S, target, test_size=0.1, random_state=42)","metadata":{"execution":{"iopub.status.busy":"2022-09-24T00:00:39.576896Z","iopub.execute_input":"2022-09-24T00:00:39.577315Z","iopub.status.idle":"2022-09-24T00:00:39.631900Z","shell.execute_reply.started":"2022-09-24T00:00:39.577280Z","shell.execute_reply":"2022-09-24T00:00:39.630811Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\nsvc = SVC(C= 0.5, probability=True)\nsvc.fit(X_train, y_train)","metadata":{"execution":{"iopub.status.busy":"2022-09-23T23:54:04.484966Z","iopub.execute_input":"2022-09-23T23:54:04.485361Z","iopub.status.idle":"2022-09-23T23:57:39.443035Z","shell.execute_reply.started":"2022-09-23T23:54:04.485329Z","shell.execute_reply":"2022-09-23T23:57:39.441600Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\nval_preds = svc.predict_proba(X_val)[:,1]","metadata":{"execution":{"iopub.status.busy":"2022-09-23T23:58:14.788006Z","iopub.execute_input":"2022-09-23T23:58:14.788421Z","iopub.status.idle":"2022-09-23T23:58:19.921347Z","shell.execute_reply.started":"2022-09-23T23:58:14.788385Z","shell.execute_reply":"2022-09-23T23:58:19.920215Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"val_preds","metadata":{"execution":{"iopub.status.busy":"2022-09-23T23:58:21.373154Z","iopub.execute_input":"2022-09-23T23:58:21.374277Z","iopub.status.idle":"2022-09-23T23:58:21.382905Z","shell.execute_reply.started":"2022-09-23T23:58:21.374225Z","shell.execute_reply":"2022-09-23T23:58:21.381764Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_val","metadata":{"execution":{"iopub.status.busy":"2022-09-23T23:58:24.333120Z","iopub.execute_input":"2022-09-23T23:58:24.333861Z","iopub.status.idle":"2022-09-23T23:58:24.341081Z","shell.execute_reply.started":"2022-09-23T23:58:24.333825Z","shell.execute_reply":"2022-09-23T23:58:24.339814Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"roc_auc_score(y_val, val_preds)","metadata":{"execution":{"iopub.status.busy":"2022-09-23T23:58:26.932830Z","iopub.execute_input":"2022-09-23T23:58:26.933226Z","iopub.status.idle":"2022-09-23T23:58:26.943350Z","shell.execute_reply.started":"2022-09-23T23:58:26.933184Z","shell.execute_reply":"2022-09-23T23:58:26.942411Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"0.9999935999631359","metadata":{"execution":{"iopub.status.busy":"2022-09-23T23:58:30.575421Z","iopub.execute_input":"2022-09-23T23:58:30.576411Z","iopub.status.idle":"2022-09-23T23:58:30.582641Z","shell.execute_reply.started":"2022-09-23T23:58:30.576371Z","shell.execute_reply":"2022-09-23T23:58:30.581416Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"log_loss(y_val, val_preds)","metadata":{"execution":{"iopub.status.busy":"2022-09-23T23:58:31.878483Z","iopub.execute_input":"2022-09-23T23:58:31.878912Z","iopub.status.idle":"2022-09-23T23:58:31.889619Z","shell.execute_reply.started":"2022-09-23T23:58:31.878876Z","shell.execute_reply":"2022-09-23T23:58:31.888394Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"0.005060","metadata":{"execution":{"iopub.status.busy":"2022-09-23T23:58:39.364343Z","iopub.execute_input":"2022-09-23T23:58:39.365434Z","iopub.status.idle":"2022-09-23T23:58:39.370996Z","shell.execute_reply.started":"2022-09-23T23:58:39.365391Z","shell.execute_reply":"2022-09-23T23:58:39.370116Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_preds = svc.predict_proba(test_ENV2S)[:,1]","metadata":{"execution":{"iopub.status.busy":"2022-09-23T23:58:55.576836Z","iopub.execute_input":"2022-09-23T23:58:55.577363Z","iopub.status.idle":"2022-09-23T23:59:21.918084Z","shell.execute_reply.started":"2022-09-23T23:58:55.577321Z","shell.execute_reply":"2022-09-23T23:59:21.916901Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_preds","metadata":{"execution":{"iopub.status.busy":"2022-09-23T23:59:21.920193Z","iopub.execute_input":"2022-09-23T23:59:21.920975Z","iopub.status.idle":"2022-09-23T23:59:21.929161Z","shell.execute_reply.started":"2022-09-23T23:59:21.920912Z","shell.execute_reply":"2022-09-23T23:59:21.928004Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample_submission['id'] = ids\nsample_submission['label'] = test_preds\nsample_submission.to_csv('submission.csv', index=False)\nsample_submission.head()","metadata":{"execution":{"iopub.status.busy":"2022-09-24T00:00:09.089677Z","iopub.execute_input":"2022-09-24T00:00:09.090142Z","iopub.status.idle":"2022-09-24T00:00:09.142034Z","shell.execute_reply.started":"2022-09-24T00:00:09.090102Z","shell.execute_reply":"2022-09-24T00:00:09.140736Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]}]}