{"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":3362,"databundleVersionId":31148,"sourceType":"competition"}],"dockerImageVersionId":30732,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"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":"2024-06-15T15:59:53.860663Z","iopub.execute_input":"2024-06-15T15:59:53.861513Z","iopub.status.idle":"2024-06-15T15:59:54.902859Z","shell.execute_reply.started":"2024-06-15T15:59:53.861471Z","shell.execute_reply":"2024-06-15T15:59:54.901471Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import zipfile\nimport os\n\n# Define paths to the zip files\ntrain_zip_path = '/kaggle/input/dogs-vs-cats/train.zip'\ntest_zip_path = '/kaggle/input/dogs-vs-cats/test1.zip'\n\n# Create directories to extract files\nos.makedirs('/kaggle/working/train', exist_ok=True)\nos.makedirs('/kaggle/working/test1', exist_ok=True)\n\n# Extract train dataset\nwith zipfile.ZipFile(train_zip_path, 'r') as zip_ref:\n    zip_ref.extractall('/kaggle/working/train')\n\n# Extract test dataset\nwith zipfile.ZipFile(test_zip_path, 'r') as zip_ref:\n    zip_ref.extractall('/kaggle/working/test1')\n","metadata":{"execution":{"iopub.status.busy":"2024-06-15T16:04:48.646514Z","iopub.execute_input":"2024-06-15T16:04:48.647823Z","iopub.status.idle":"2024-06-15T16:05:05.011627Z","shell.execute_reply.started":"2024-06-15T16:04:48.647773Z","shell.execute_reply":"2024-06-15T16:05:05.010644Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport cv2\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.svm import SVC\nfrom sklearn.metrics import accuracy_score\n","metadata":{"execution":{"iopub.status.busy":"2024-06-15T16:05:34.952933Z","iopub.execute_input":"2024-06-15T16:05:34.953874Z","iopub.status.idle":"2024-06-15T16:05:35.948993Z","shell.execute_reply.started":"2024-06-15T16:05:34.953836Z","shell.execute_reply":"2024-06-15T16:05:35.947914Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"path = '/kaggle/working/train/train/'  # The path to the training dataset\nimages = []\nlabels = []\n\nfor img in os.listdir(path):\n    img_path = os.path.join(path, img)\n    image = cv2.imread(img_path)\n    image = cv2.resize(image, (64, 64))\n    images.append(image)\n\n    if 'cat' in img:\n        labels.append(0)\n    else:\n        labels.append(1)\n\nimages = np.array(images)\nlabels = np.array(labels)\n","metadata":{"execution":{"iopub.status.busy":"2024-06-15T16:05:51.827739Z","iopub.execute_input":"2024-06-15T16:05:51.82817Z","iopub.status.idle":"2024-06-15T16:06:15.86716Z","shell.execute_reply.started":"2024-06-15T16:05:51.828136Z","shell.execute_reply":"2024-06-15T16:06:15.866102Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"images = images / 255.0  # Normalize images\nimages = images.reshape(images.shape[0], -1)  # Flatten images\n\nX_train, X_test, y_train, y_test = train_test_split(images, labels, test_size=0.2, random_state=42)\n","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"svm = SVC(kernel='linear')\nsvm.fit(X_train, y_train)\n","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred = svm.predict(X_test)\naccuracy = accuracy_score(y_test, y_pred)\nprint(f'Accuracy: {accuracy}')","metadata":{},"execution_count":null,"outputs":[]}]}