{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.12.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceType":"competition","sourceId":5441,"databundleVersionId":38425},{"sourceType":"datasetVersion","sourceId":30378,"datasetId":23777,"databundleVersionId":30535}],"dockerImageVersionId":31328,"isInternetEnabled":false,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"!pip install opencv-python","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2026-04-20T17:21:47.036238Z","iopub.execute_input":"2026-04-20T17:21:47.036734Z","iopub.status.idle":"2026-04-20T17:21:51.053089Z","shell.execute_reply.started":"2026-04-20T17:21:47.036698Z","shell.execute_reply":"2026-04-20T17:21:51.051637Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import os\n\nfor root, dirs, files in os.walk(\"/kaggle/input\"):\n    print(root)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-04-20T17:21:51.056075Z","iopub.execute_input":"2026-04-20T17:21:51.057044Z","iopub.status.idle":"2026-04-20T17:21:55.618950Z","shell.execute_reply.started":"2026-04-20T17:21:51.056985Z","shell.execute_reply":"2026-04-20T17:21:55.617724Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import os\nprint(os.listdir(\"/kaggle/input/datasets\"))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-04-20T17:21:55.620339Z","iopub.execute_input":"2026-04-20T17:21:55.620741Z","iopub.status.idle":"2026-04-20T17:21:55.628155Z","shell.execute_reply.started":"2026-04-20T17:21:55.620699Z","shell.execute_reply":"2026-04-20T17:21:55.626860Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"for root, dirs, files in os.walk(\"/kaggle/input/datasets\"):\n    print(root)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-04-20T17:21:55.629794Z","iopub.execute_input":"2026-04-20T17:21:55.631535Z","iopub.status.idle":"2026-04-20T17:21:55.703987Z","shell.execute_reply.started":"2026-04-20T17:21:55.631458Z","shell.execute_reply":"2026-04-20T17:21:55.702695Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"aminul_data_dir = \"/kaggle/input/competitions/dogs-vs-cats-redux-kernels-edition\"\naminul_categories = [\"cats\", \"dogs\"]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-04-20T17:21:55.706883Z","iopub.execute_input":"2026-04-20T17:21:55.707208Z","iopub.status.idle":"2026-04-20T17:21:55.712797Z","shell.execute_reply.started":"2026-04-20T17:21:55.707170Z","shell.execute_reply":"2026-04-20T17:21:55.711703Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import os\n\nfor root, dirs, files in os.walk(\"/kaggle/input\"):\n    print(root)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-04-20T17:21:55.713859Z","iopub.execute_input":"2026-04-20T17:21:55.714362Z","iopub.status.idle":"2026-04-20T17:21:55.801477Z","shell.execute_reply.started":"2026-04-20T17:21:55.714322Z","shell.execute_reply":"2026-04-20T17:21:55.800397Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"aminul_data_dir = \"/kaggle/input/datasets/tongpython/cat-and-dog/training_set/training_set\"\naminul_categories = [\"cats\", \"dogs\"]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-04-20T17:21:55.803293Z","iopub.execute_input":"2026-04-20T17:21:55.804361Z","iopub.status.idle":"2026-04-20T17:21:55.809470Z","shell.execute_reply.started":"2026-04-20T17:21:55.804320Z","shell.execute_reply":"2026-04-20T17:21:55.807913Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import os\n\nprint(os.listdir(aminul_data_dir))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-04-20T17:21:55.810821Z","iopub.execute_input":"2026-04-20T17:21:55.811788Z","iopub.status.idle":"2026-04-20T17:21:55.837057Z","shell.execute_reply.started":"2026-04-20T17:21:55.811750Z","shell.execute_reply":"2026-04-20T17:21:55.835576Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import cv2\nimport numpy as np\n\nIMG_SIZE = 64\n\naminul_X = []\naminul_y = []\n\nfor category in aminul_categories:\n    path = os.path.join(aminul_data_dir, category)\n    label = aminul_categories.index(category)\n\n    print(\"Loading:\", category)\n\n    for img in os.listdir(path)[:1500]:\n        try:\n            img_path = os.path.join(path, img)\n            img_array = cv2.imread(img_path)\n\n            gray = cv2.cvtColor(img_array, cv2.COLOR_BGR2GRAY)\n            resized = cv2.resize(gray, (IMG_SIZE, IMG_SIZE))\n\n            aminul_X.append(resized.flatten())\n            aminul_y.append(label)\n        except:\n            pass\n\naminul_X = np.array(aminul_X) / 255.0\naminul_y = np.array(aminul_y)\n\nprint(\"Shape:\", aminul_X.shape)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-04-20T17:21:55.838354Z","iopub.execute_input":"2026-04-20T17:21:55.838705Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\n\naminul_X_train, aminul_X_test, aminul_y_train, aminul_y_test = train_test_split(\n    aminul_X, aminul_y, test_size=0.2, random_state=42\n)\n\nprint(aminul_X_train.shape, aminul_X_test.shape)","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from sklearn.naive_bayes import GaussianNB\nfrom sklearn.tree import DecisionTreeClassifier\nfrom sklearn.svm import SVC\n\naminul_nb = GaussianNB()\naminul_dt = DecisionTreeClassifier()\naminul_svm = SVC(probability=True)\n\naminul_nb.fit(aminul_X_train, aminul_y_train)\naminul_dt.fit(aminul_X_train, aminul_y_train)\naminul_svm.fit(aminul_X_train, aminul_y_train)","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from sklearn.ensemble import VotingClassifier\n\naminul_ensemble = VotingClassifier(\n    estimators=[\n        ('nb', aminul_nb),\n        ('dt', aminul_dt),\n        ('svm', aminul_svm)\n    ],\n    voting='soft'\n)\n\naminul_ensemble.fit(aminul_X_train, aminul_y_train)","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from sklearn.metrics import accuracy_score, precision_score, f1_score, confusion_matrix\n\naminul_pred = aminul_ensemble.predict(aminul_X_test)\n\nprint(\"Accuracy:\", accuracy_score(aminul_y_test, aminul_pred))\nprint(\"Precision:\", precision_score(aminul_y_test, aminul_pred))\nprint(\"F1 Score:\", f1_score(aminul_y_test, aminul_pred))\n\naminul_cm = confusion_matrix(aminul_y_test, aminul_pred)\nprint(\"Confusion Matrix:\\n\", aminul_cm)","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import matplotlib.pyplot as plt\n\nplt.imshow(aminul_cm)\nplt.title(\"Aminul - Confusion Matrix\")\nplt.colorbar()\nplt.xlabel(\"Predicted\")\nplt.ylabel(\"Actual\")\nplt.show()","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}