{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.12.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[],"dockerImageVersionId":28755,"isInternetEnabled":false,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import os\nimport zipfile\nimport cv2\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.svm import SVC\nfrom sklearn.preprocessing import StandardScaler\nfrom sklearn.metrics import accuracy_score","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-22T09:12:43.417711Z","iopub.execute_input":"2026-07-22T09:12:43.418070Z","iopub.status.idle":"2026-07-22T09:12:43.423221Z","shell.execute_reply.started":"2026-07-22T09:12:43.418035Z","shell.execute_reply":"2026-07-22T09:12:43.422344Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"zip_path=(\"/kaggle/input/competitions/dogs-vs-cats/train.zip\")\nwith zipfile.ZipFile(zip_path,\"r\") as zip_ref:\n    zip_ref.extractall(\"/kaggle/working/\")\n\nprint(\"Dataset Extracted Successfully\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-22T09:12:47.498780Z","iopub.execute_input":"2026-07-22T09:12:47.499144Z","iopub.status.idle":"2026-07-22T09:12:53.807282Z","shell.execute_reply.started":"2026-07-22T09:12:47.499114Z","shell.execute_reply":"2026-07-22T09:12:53.806351Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"dataset_path=\"/kaggle/working/train\"\n\nX=[]\ny=[]\n\nIMG_SIZE=64","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-22T09:13:02.695047Z","iopub.execute_input":"2026-07-22T09:13:02.695684Z","iopub.status.idle":"2026-07-22T09:13:02.699572Z","shell.execute_reply.started":"2026-07-22T09:13:02.695650Z","shell.execute_reply":"2026-07-22T09:13:02.698763Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"cat_images=[img for img in os.listdir(dataset_path) if img.startswith(\"cat\")][:2500]\ndog_images=[img for img in os.listdir(dataset_path) if img.startswith(\"dog\")][:2500]\n\nfor img_name in cat_images:\n    img_path=os.path.join(dataset_path,img_name)\n    img=cv2.imread(img_path,cv2.IMREAD_GRAYSCALE)\n    img=cv2.resize(img,(IMG_SIZE,IMG_SIZE))\n    X.append(img.flatten())\n    y.append(0)\n\nfor img_name in dog_images:\n    img_path=os.path.join(dataset_path,img_name)\n    img=cv2.imread(img_path,cv2.IMREAD_GRAYSCALE)\n    img=cv2.resize(img,(IMG_SIZE,IMG_SIZE))\n    X.append(img.flatten())\n    y.append(1)\n\nprint(len(X))\nprint(len(y))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-22T09:13:06.090832Z","iopub.execute_input":"2026-07-22T09:13:06.091189Z","iopub.status.idle":"2026-07-22T09:13:09.443216Z","shell.execute_reply.started":"2026-07-22T09:13:06.091158Z","shell.execute_reply":"2026-07-22T09:13:09.442247Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"X=np.array(X)\ny=np.array(y)\n\nprint(X.shape)\nprint(y.shape)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-22T09:13:13.865625Z","iopub.execute_input":"2026-07-22T09:13:13.865993Z","iopub.status.idle":"2026-07-22T09:13:13.886119Z","shell.execute_reply.started":"2026-07-22T09:13:13.865962Z","shell.execute_reply":"2026-07-22T09:13:13.885358Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"X_train,X_test,y_train,y_test=train_test_split(\n    X,y,test_size=0.2,random_state=42,stratify=y\n)\n\nprint(X_train.shape)\nprint(X_test.shape)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-22T09:13:19.486636Z","iopub.execute_input":"2026-07-22T09:13:19.487366Z","iopub.status.idle":"2026-07-22T09:13:19.506181Z","shell.execute_reply.started":"2026-07-22T09:13:19.487330Z","shell.execute_reply":"2026-07-22T09:13:19.505213Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"scaler=StandardScaler()\n\nX_train=scaler.fit_transform(X_train)\nX_test=scaler.transform(X_test)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-22T09:13:22.915040Z","iopub.execute_input":"2026-07-22T09:13:22.915365Z","iopub.status.idle":"2026-07-22T09:13:23.221123Z","shell.execute_reply.started":"2026-07-22T09:13:22.915328Z","shell.execute_reply":"2026-07-22T09:13:23.220076Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"model=SVC(kernel=\"rbf\",C=10,gamma=\"scale\")\n\nmodel.fit(X_train,y_train)\n\nprint(\"Model Trained Successfully\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-22T09:13:28.034415Z","iopub.execute_input":"2026-07-22T09:13:28.035132Z","iopub.status.idle":"2026-07-22T09:14:15.198086Z","shell.execute_reply.started":"2026-07-22T09:13:28.035098Z","shell.execute_reply":"2026-07-22T09:14:15.197219Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"y_pred=model.predict(X_test)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-22T09:14:20.489425Z","iopub.execute_input":"2026-07-22T09:14:20.490033Z","iopub.status.idle":"2026-07-22T09:14:36.856522Z","shell.execute_reply.started":"2026-07-22T09:14:20.490000Z","shell.execute_reply":"2026-07-22T09:14:36.855663Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"accuracy=accuracy_score(y_test,y_pred)\n\nprint(\"Accuracy:\",accuracy)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-22T09:14:41.184607Z","iopub.execute_input":"2026-07-22T09:14:41.185496Z","iopub.status.idle":"2026-07-22T09:14:41.191513Z","shell.execute_reply.started":"2026-07-22T09:14:41.185457Z","shell.execute_reply":"2026-07-22T09:14:41.190622Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from sklearn.metrics import classification_report\nprint(classification_report(y_test,y_pred,zero_division=0))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-22T09:14:45.324860Z","iopub.execute_input":"2026-07-22T09:14:45.325196Z","iopub.status.idle":"2026-07-22T09:14:45.339767Z","shell.execute_reply.started":"2026-07-22T09:14:45.325167Z","shell.execute_reply":"2026-07-22T09:14:45.338994Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nfrom sklearn.metrics import confusion_matrix\ncm=confusion_matrix(y_test,y_pred)\n\nprint(cm)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-22T09:14:49.234608Z","iopub.execute_input":"2026-07-22T09:14:49.234968Z","iopub.status.idle":"2026-07-22T09:14:49.242337Z","shell.execute_reply.started":"2026-07-22T09:14:49.234934Z","shell.execute_reply":"2026-07-22T09:14:49.241522Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"plt.imshow(cm,cmap=\"Blues\")\nplt.title(\"Confusion Matrix\")\nplt.colorbar()\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-22T09:14:53.651347Z","iopub.execute_input":"2026-07-22T09:14:53.651657Z","iopub.status.idle":"2026-07-22T09:14:53.913346Z","shell.execute_reply.started":"2026-07-22T09:14:53.651628Z","shell.execute_reply":"2026-07-22T09:14:53.912502Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"plt.figure(figsize=(12,8))\n\nfor i in range(6):\n    plt.subplot(2,3,i+1)\n    plt.imshow(X_test[i].reshape(64,64),cmap=\"gray\")\n\n    if y_pred[i]==0:\n        plt.title(\"Cat\")\n    else:\n        plt.title(\"Dog\")\n\n    plt.axis(\"off\")\n\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-22T09:15:46.423844Z","iopub.execute_input":"2026-07-22T09:15:46.424154Z","iopub.status.idle":"2026-07-22T09:15:46.845720Z","shell.execute_reply.started":"2026-07-22T09:15:46.424125Z","shell.execute_reply":"2026-07-22T09:15:46.844870Z"}},"outputs":[],"execution_count":null}]}