{"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\nimport cudf\nimport cupy as cp\nfrom cuml.svm import SVC\nfrom sklearn.model_selection import KFold, train_test_split\nfrom sklearn.metrics import roc_auc_score, log_loss\n","metadata":{"execution":{"iopub.status.busy":"2022-08-12T14:17:24.938341Z","iopub.execute_input":"2022-08-12T14:17:24.939092Z","iopub.status.idle":"2022-08-12T14:17:30.283330Z","shell.execute_reply.started":"2022-08-12T14:17:24.938942Z","shell.execute_reply":"2022-08-12T14:17:30.282066Z"},"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-08-12T14:17:34.768146Z","iopub.execute_input":"2022-08-12T14:17:34.768520Z","iopub.status.idle":"2022-08-12T14:17:34.775307Z","shell.execute_reply.started":"2022-08-12T14:17:34.768490Z","shell.execute_reply":"2022-08-12T14:17:34.773872Z"},"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-08-12T14:17:37.799442Z","iopub.execute_input":"2022-08-12T14:17:37.799815Z","iopub.status.idle":"2022-08-12T14:17:37.832239Z","shell.execute_reply.started":"2022-08-12T14:17:37.799784Z","shell.execute_reply":"2022-08-12T14:17:37.831101Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample_submission.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-12T14:17:42.127274Z","iopub.execute_input":"2022-08-12T14:17:42.127901Z","iopub.status.idle":"2022-08-12T14:17:42.139875Z","shell.execute_reply.started":"2022-08-12T14:17:42.127865Z","shell.execute_reply":"2022-08-12T14:17:42.138539Z"},"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 = 224","metadata":{"execution":{"iopub.status.busy":"2022-08-12T14:17:49.110026Z","iopub.execute_input":"2022-08-12T14:17:49.111075Z","iopub.status.idle":"2022-08-12T14:17:49.115529Z","shell.execute_reply.started":"2022-08-12T14:17:49.111008Z","shell.execute_reply":"2022-08-12T14:17:49.114526Z"},"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-08-12T14:17:50.015439Z","iopub.execute_input":"2022-08-12T14:17:50.015795Z","iopub.status.idle":"2022-08-12T14:17:50.045821Z","shell.execute_reply.started":"2022-08-12T14:17:50.015765Z","shell.execute_reply":"2022-08-12T14:17:50.044858Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_image_list","metadata":{"execution":{"iopub.status.busy":"2022-08-12T14:17:51.891702Z","iopub.execute_input":"2022-08-12T14:17:51.892339Z","iopub.status.idle":"2022-08-12T14:17:51.900434Z","shell.execute_reply.started":"2022-08-12T14:17:51.892298Z","shell.execute_reply":"2022-08-12T14:17:51.899359Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_image_list","metadata":{"execution":{"iopub.status.busy":"2022-08-12T14:17:53.320292Z","iopub.execute_input":"2022-08-12T14:17:53.320663Z","iopub.status.idle":"2022-08-12T14:17:53.327771Z","shell.execute_reply.started":"2022-08-12T14:17:53.320630Z","shell.execute_reply":"2022-08-12T14:17:53.326634Z"},"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-08-12T14:17:55.514191Z","iopub.execute_input":"2022-08-12T14:17:55.515260Z","iopub.status.idle":"2022-08-12T14:17:55.534080Z","shell.execute_reply.started":"2022-08-12T14:17:55.515190Z","shell.execute_reply":"2022-08-12T14:17:55.532940Z"},"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-08-12T14:18:00.134125Z","iopub.execute_input":"2022-08-12T14:18:00.134774Z","iopub.status.idle":"2022-08-12T14:18:00.145771Z","shell.execute_reply.started":"2022-08-12T14:18:00.134740Z","shell.execute_reply":"2022-08-12T14:18:00.144784Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"target","metadata":{"execution":{"iopub.status.busy":"2022-08-12T14:18:01.226710Z","iopub.execute_input":"2022-08-12T14:18:01.227097Z","iopub.status.idle":"2022-08-12T14:18:01.235982Z","shell.execute_reply.started":"2022-08-12T14:18:01.227062Z","shell.execute_reply":"2022-08-12T14:18:01.234706Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_EB7_ns = np.load('../input/cats-and-dogs-embedded-data/cats_and_dogs_4/cats_and_dogs_4/train_EB7_ns.npy')\ntest_EB7_ns = np.load('../input/cats-and-dogs-embedded-data/cats_and_dogs_4/cats_and_dogs_4/test_EB7_ns.npy')","metadata":{"execution":{"iopub.status.busy":"2022-08-12T14:18:03.731436Z","iopub.execute_input":"2022-08-12T14:18:03.731796Z","iopub.status.idle":"2022-08-12T14:18:07.311932Z","shell.execute_reply.started":"2022-08-12T14:18:03.731764Z","shell.execute_reply":"2022-08-12T14:18:07.310888Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_EB7_ns.shape","metadata":{"execution":{"iopub.status.busy":"2022-08-12T14:26:44.207237Z","iopub.execute_input":"2022-08-12T14:26:44.207873Z","iopub.status.idle":"2022-08-12T14:26:44.215315Z","shell.execute_reply.started":"2022-08-12T14:26:44.207836Z","shell.execute_reply":"2022-08-12T14:26:44.214104Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train, X_val, y_train, y_val = train_test_split(train_EB7_ns, target, test_size=0.1, random_state=42)","metadata":{"execution":{"iopub.status.busy":"2022-08-12T14:26:48.102850Z","iopub.execute_input":"2022-08-12T14:26:48.103267Z","iopub.status.idle":"2022-08-12T14:26:48.201164Z","shell.execute_reply.started":"2022-08-12T14:26:48.103231Z","shell.execute_reply":"2022-08-12T14:26:48.200101Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\nsvc = SVC(C= 0.07, probability=True)\nsvc.fit(X_train, y_train)","metadata":{"execution":{"iopub.status.busy":"2022-08-12T14:26:50.856728Z","iopub.execute_input":"2022-08-12T14:26:50.857145Z","iopub.status.idle":"2022-08-12T14:27:01.678010Z","shell.execute_reply.started":"2022-08-12T14:26:50.857110Z","shell.execute_reply":"2022-08-12T14:27:01.676886Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"val_preds = svc.predict_proba(X_val)[:,1]","metadata":{"execution":{"iopub.status.busy":"2022-08-12T14:27:15.902804Z","iopub.execute_input":"2022-08-12T14:27:15.903291Z","iopub.status.idle":"2022-08-12T14:27:16.048611Z","shell.execute_reply.started":"2022-08-12T14:27:15.903248Z","shell.execute_reply":"2022-08-12T14:27:16.047309Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"val_preds","metadata":{"execution":{"iopub.status.busy":"2022-08-12T14:27:24.082066Z","iopub.execute_input":"2022-08-12T14:27:24.083235Z","iopub.status.idle":"2022-08-12T14:27:24.090586Z","shell.execute_reply.started":"2022-08-12T14:27:24.083187Z","shell.execute_reply":"2022-08-12T14:27:24.089473Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_val","metadata":{"execution":{"iopub.status.busy":"2022-08-12T14:28:09.163127Z","iopub.execute_input":"2022-08-12T14:28:09.163499Z","iopub.status.idle":"2022-08-12T14:28:09.171015Z","shell.execute_reply.started":"2022-08-12T14:28:09.163467Z","shell.execute_reply":"2022-08-12T14:28:09.169865Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"roc_auc_score(y_val, val_preds)","metadata":{"execution":{"iopub.status.busy":"2022-08-12T14:28:11.058732Z","iopub.execute_input":"2022-08-12T14:28:11.059130Z","iopub.status.idle":"2022-08-12T14:28:11.070127Z","shell.execute_reply.started":"2022-08-12T14:28:11.059096Z","shell.execute_reply":"2022-08-12T14:28:11.069056Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"0.9999935999631359","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"log_loss(y_val, val_preds)","metadata":{"execution":{"iopub.status.busy":"2022-08-12T14:28:39.787943Z","iopub.execute_input":"2022-08-12T14:28:39.788692Z","iopub.status.idle":"2022-08-12T14:28:39.798278Z","shell.execute_reply.started":"2022-08-12T14:28:39.788656Z","shell.execute_reply":"2022-08-12T14:28:39.797168Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"0.005060","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_preds = svc.predict_proba(test_EB7_ns)[:,1]","metadata":{"execution":{"iopub.status.busy":"2022-08-12T14:28:54.348155Z","iopub.execute_input":"2022-08-12T14:28:54.349172Z","iopub.status.idle":"2022-08-12T14:28:54.880775Z","shell.execute_reply.started":"2022-08-12T14:28:54.349128Z","shell.execute_reply":"2022-08-12T14:28:54.879710Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_preds","metadata":{"execution":{"iopub.status.busy":"2022-08-12T14:28:55.671484Z","iopub.execute_input":"2022-08-12T14:28:55.672714Z","iopub.status.idle":"2022-08-12T14:28:55.680742Z","shell.execute_reply.started":"2022-08-12T14:28:55.672663Z","shell.execute_reply":"2022-08-12T14:28:55.679491Z"},"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-08-12T14:28:58.038091Z","iopub.execute_input":"2022-08-12T14:28:58.038784Z","iopub.status.idle":"2022-08-12T14:28:58.090771Z","shell.execute_reply.started":"2022-08-12T14:28:58.038748Z","shell.execute_reply":"2022-08-12T14:28:58.089683Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]}]}