{"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":"!pip install scikit-learn-intelex -q --progress-bar off","metadata":{"execution":{"iopub.status.busy":"2022-08-12T14:37:51.364614Z","iopub.execute_input":"2022-08-12T14:37:51.365415Z","iopub.status.idle":"2022-08-12T14:38:03.419678Z","shell.execute_reply.started":"2022-08-12T14:37:51.365307Z","shell.execute_reply":"2022-08-12T14:38:03.418580Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearnex import patch_sklearn\npatch_sklearn()","metadata":{"execution":{"iopub.status.busy":"2022-08-12T14:38:07.742986Z","iopub.execute_input":"2022-08-12T14:38:07.743357Z","iopub.status.idle":"2022-08-12T14:38:08.900483Z","shell.execute_reply.started":"2022-08-12T14:38:07.743322Z","shell.execute_reply":"2022-08-12T14:38:08.898910Z"},"trusted":true},"execution_count":null,"outputs":[]},{"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-08-12T14:38:26.901508Z","iopub.execute_input":"2022-08-12T14:38:26.901918Z","iopub.status.idle":"2022-08-12T14:38:26.907501Z","shell.execute_reply.started":"2022-08-12T14:38:26.901883Z","shell.execute_reply":"2022-08-12T14:38:26.906289Z"},"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:38:41.741533Z","iopub.execute_input":"2022-08-12T14:38:41.742606Z","iopub.status.idle":"2022-08-12T14:38:41.748503Z","shell.execute_reply.started":"2022-08-12T14:38:41.742553Z","shell.execute_reply":"2022-08-12T14:38:41.747129Z"},"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:38:45.142615Z","iopub.execute_input":"2022-08-12T14:38:45.142990Z","iopub.status.idle":"2022-08-12T14:38:45.170792Z","shell.execute_reply.started":"2022-08-12T14:38:45.142959Z","shell.execute_reply":"2022-08-12T14:38:45.169607Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample_submission.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-12T14:38:49.332660Z","iopub.execute_input":"2022-08-12T14:38:49.333289Z","iopub.status.idle":"2022-08-12T14:38:49.343206Z","shell.execute_reply.started":"2022-08-12T14:38:49.333253Z","shell.execute_reply":"2022-08-12T14:38:49.342235Z"},"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:38:51.034251Z","iopub.execute_input":"2022-08-12T14:38:51.037005Z","iopub.status.idle":"2022-08-12T14:38:51.041468Z","shell.execute_reply.started":"2022-08-12T14:38:51.036966Z","shell.execute_reply":"2022-08-12T14:38:51.040495Z"},"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:38:54.394756Z","iopub.execute_input":"2022-08-12T14:38:54.395167Z","iopub.status.idle":"2022-08-12T14:38:54.427827Z","shell.execute_reply.started":"2022-08-12T14:38:54.395134Z","shell.execute_reply":"2022-08-12T14:38:54.426988Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_image_list","metadata":{"execution":{"iopub.status.busy":"2022-08-12T14:38:56.213639Z","iopub.execute_input":"2022-08-12T14:38:56.214269Z","iopub.status.idle":"2022-08-12T14:38:56.220915Z","shell.execute_reply.started":"2022-08-12T14:38:56.214233Z","shell.execute_reply":"2022-08-12T14:38:56.219792Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_image_list","metadata":{"execution":{"iopub.status.busy":"2022-08-12T14:38:57.617169Z","iopub.execute_input":"2022-08-12T14:38:57.617521Z","iopub.status.idle":"2022-08-12T14:38:57.623973Z","shell.execute_reply.started":"2022-08-12T14:38:57.617490Z","shell.execute_reply":"2022-08-12T14:38:57.622959Z"},"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:38:58.683124Z","iopub.execute_input":"2022-08-12T14:38:58.683728Z","iopub.status.idle":"2022-08-12T14:38:58.701747Z","shell.execute_reply.started":"2022-08-12T14:38:58.683679Z","shell.execute_reply":"2022-08-12T14:38:58.700781Z"},"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:39:00.317217Z","iopub.execute_input":"2022-08-12T14:39:00.317579Z","iopub.status.idle":"2022-08-12T14:39:00.327614Z","shell.execute_reply.started":"2022-08-12T14:39:00.317547Z","shell.execute_reply":"2022-08-12T14:39:00.326411Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"target","metadata":{"execution":{"iopub.status.busy":"2022-08-12T14:39:01.890700Z","iopub.execute_input":"2022-08-12T14:39:01.891578Z","iopub.status.idle":"2022-08-12T14:39:01.897603Z","shell.execute_reply.started":"2022-08-12T14:39:01.891540Z","shell.execute_reply":"2022-08-12T14:39:01.896702Z"},"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:39:04.022446Z","iopub.execute_input":"2022-08-12T14:39:04.022827Z","iopub.status.idle":"2022-08-12T14:39:07.260812Z","shell.execute_reply.started":"2022-08-12T14:39:04.022788Z","shell.execute_reply":"2022-08-12T14:39:07.259764Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_EB7_ns.shape","metadata":{"execution":{"iopub.status.busy":"2022-08-12T14:39:07.264677Z","iopub.execute_input":"2022-08-12T14:39:07.265630Z","iopub.status.idle":"2022-08-12T14:39:07.273740Z","shell.execute_reply.started":"2022-08-12T14:39:07.265592Z","shell.execute_reply":"2022-08-12T14:39:07.272708Z"},"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:39:08.727785Z","iopub.execute_input":"2022-08-12T14:39:08.728453Z","iopub.status.idle":"2022-08-12T14:39:08.839318Z","shell.execute_reply.started":"2022-08-12T14:39:08.728416Z","shell.execute_reply":"2022-08-12T14:39:08.838327Z"},"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:39:09.907469Z","iopub.execute_input":"2022-08-12T14:39:09.909933Z","iopub.status.idle":"2022-08-12T14:40:16.976053Z","shell.execute_reply.started":"2022-08-12T14:39:09.909898Z","shell.execute_reply":"2022-08-12T14:40:16.974970Z"},"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-08-12T14:41:28.352665Z","iopub.execute_input":"2022-08-12T14:41:28.353314Z","iopub.status.idle":"2022-08-12T14:41:28.525252Z","shell.execute_reply.started":"2022-08-12T14:41:28.353273Z","shell.execute_reply":"2022-08-12T14:41:28.523504Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"val_preds","metadata":{"execution":{"iopub.status.busy":"2022-08-12T14:42:06.209544Z","iopub.execute_input":"2022-08-12T14:42:06.209937Z","iopub.status.idle":"2022-08-12T14:42:06.217513Z","shell.execute_reply.started":"2022-08-12T14:42:06.209905Z","shell.execute_reply":"2022-08-12T14:42:06.216442Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_val","metadata":{"execution":{"iopub.status.busy":"2022-08-12T14:42:09.609885Z","iopub.execute_input":"2022-08-12T14:42:09.610551Z","iopub.status.idle":"2022-08-12T14:42:09.617087Z","shell.execute_reply.started":"2022-08-12T14:42:09.610517Z","shell.execute_reply":"2022-08-12T14:42:09.615966Z"},"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:42:11.664306Z","iopub.execute_input":"2022-08-12T14:42:11.664712Z","iopub.status.idle":"2022-08-12T14:42:11.677123Z","shell.execute_reply.started":"2022-08-12T14:42:11.664677Z","shell.execute_reply":"2022-08-12T14:42:11.675898Z"},"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:42:21.612180Z","iopub.execute_input":"2022-08-12T14:42:21.612546Z","iopub.status.idle":"2022-08-12T14:42:21.622975Z","shell.execute_reply.started":"2022-08-12T14:42:21.612516Z","shell.execute_reply":"2022-08-12T14:42:21.621851Z"},"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:42:31.187585Z","iopub.execute_input":"2022-08-12T14:42:31.188209Z","iopub.status.idle":"2022-08-12T14:42:31.947486Z","shell.execute_reply.started":"2022-08-12T14:42:31.188175Z","shell.execute_reply":"2022-08-12T14:42:31.946501Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_preds","metadata":{"execution":{"iopub.status.busy":"2022-08-12T14:42:34.088442Z","iopub.execute_input":"2022-08-12T14:42:34.088932Z","iopub.status.idle":"2022-08-12T14:42:34.097746Z","shell.execute_reply.started":"2022-08-12T14:42:34.088897Z","shell.execute_reply":"2022-08-12T14:42:34.096291Z"},"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:42:35.390977Z","iopub.execute_input":"2022-08-12T14:42:35.391375Z","iopub.status.idle":"2022-08-12T14:42:35.437709Z","shell.execute_reply.started":"2022-08-12T14:42:35.391345Z","shell.execute_reply":"2022-08-12T14:42:35.436685Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]}]}