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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cells": [
|
| 3 |
+
{
|
| 4 |
+
"cell_type": "code",
|
| 5 |
+
"execution_count": null,
|
| 6 |
+
"metadata": {
|
| 7 |
+
"id": "TjaG3WllZX3Y"
|
| 8 |
+
},
|
| 9 |
+
"outputs": [],
|
| 10 |
+
"source": [
|
| 11 |
+
"import numpy as np\n",
|
| 12 |
+
"import pandas as pd\n",
|
| 13 |
+
"from sklearn.model_selection import train_test_split\n",
|
| 14 |
+
"from sklearn.linear_model import LogisticRegression\n",
|
| 15 |
+
"from sklearn.metrics import accuracy_score\n",
|
| 16 |
+
"\n",
|
| 17 |
+
"import warnings\n",
|
| 18 |
+
"warnings.filterwarnings('ignore')"
|
| 19 |
+
]
|
| 20 |
+
},
|
| 21 |
+
{
|
| 22 |
+
"cell_type": "code",
|
| 23 |
+
"source": [
|
| 24 |
+
"import re\n",
|
| 25 |
+
"import nltk\n",
|
| 26 |
+
"import string\n",
|
| 27 |
+
"from nltk.corpus import stopwords\n",
|
| 28 |
+
"from nltk.stem import WordNetLemmatizer\n",
|
| 29 |
+
"\n",
|
| 30 |
+
"nltk.download('punkt')\n",
|
| 31 |
+
"nltk.download('stopwords')\n",
|
| 32 |
+
"nltk.download('wordnet')"
|
| 33 |
+
],
|
| 34 |
+
"metadata": {
|
| 35 |
+
"colab": {
|
| 36 |
+
"base_uri": "https://localhost:8080/"
|
| 37 |
+
},
|
| 38 |
+
"id": "s4OOuG5PQ6pJ",
|
| 39 |
+
"outputId": "2e06700b-0d23-40e0-edbf-5174a81625d1"
|
| 40 |
+
},
|
| 41 |
+
"execution_count": null,
|
| 42 |
+
"outputs": [
|
| 43 |
+
{
|
| 44 |
+
"output_type": "stream",
|
| 45 |
+
"name": "stderr",
|
| 46 |
+
"text": [
|
| 47 |
+
"[nltk_data] Downloading package punkt to /root/nltk_data...\n",
|
| 48 |
+
"[nltk_data] Package punkt is already up-to-date!\n",
|
| 49 |
+
"[nltk_data] Downloading package stopwords to /root/nltk_data...\n",
|
| 50 |
+
"[nltk_data] Package stopwords is already up-to-date!\n",
|
| 51 |
+
"[nltk_data] Downloading package wordnet to /root/nltk_data...\n",
|
| 52 |
+
"[nltk_data] Package wordnet is already up-to-date!\n"
|
| 53 |
+
]
|
| 54 |
+
},
|
| 55 |
+
{
|
| 56 |
+
"output_type": "execute_result",
|
| 57 |
+
"data": {
|
| 58 |
+
"text/plain": [
|
| 59 |
+
"True"
|
| 60 |
+
]
|
| 61 |
+
},
|
| 62 |
+
"metadata": {},
|
| 63 |
+
"execution_count": 3
|
| 64 |
+
}
|
| 65 |
+
]
|
| 66 |
+
},
|
| 67 |
+
{
|
| 68 |
+
"cell_type": "code",
|
| 69 |
+
"source": [
|
| 70 |
+
"df = pd.read_csv(\"/content/IMDB Dataset.csv\", engine=\"python\", on_bad_lines=\"skip\")\n",
|
| 71 |
+
"print(df.shape)\n",
|
| 72 |
+
"print(df.head())\n",
|
| 73 |
+
"\n"
|
| 74 |
+
],
|
| 75 |
+
"metadata": {
|
| 76 |
+
"colab": {
|
| 77 |
+
"base_uri": "https://localhost:8080/"
|
| 78 |
+
},
|
| 79 |
+
"id": "EmJ8miPsQ_ix",
|
| 80 |
+
"outputId": "9801b4f9-f496-4860-a87e-af309576af72"
|
| 81 |
+
},
|
| 82 |
+
"execution_count": null,
|
| 83 |
+
"outputs": [
|
| 84 |
+
{
|
| 85 |
+
"output_type": "stream",
|
| 86 |
+
"name": "stdout",
|
| 87 |
+
"text": [
|
| 88 |
+
"(50000, 2)\n",
|
| 89 |
+
" review sentiment\n",
|
| 90 |
+
"0 One of the other reviewers has mentioned that ... positive\n",
|
| 91 |
+
"1 A wonderful little production. <br /><br />The... positive\n",
|
| 92 |
+
"2 I thought this was a wonderful way to spend ti... positive\n",
|
| 93 |
+
"3 Basically there's a family where a little boy ... negative\n",
|
| 94 |
+
"4 Petter Mattei's \"Love in the Time of Money\" is... positive\n"
|
| 95 |
+
]
|
| 96 |
+
}
|
| 97 |
+
]
|
| 98 |
+
},
|
| 99 |
+
{
|
| 100 |
+
"cell_type": "code",
|
| 101 |
+
"source": [
|
| 102 |
+
"nltk.download(\"punkt_tab\")"
|
| 103 |
+
],
|
| 104 |
+
"metadata": {
|
| 105 |
+
"colab": {
|
| 106 |
+
"base_uri": "https://localhost:8080/"
|
| 107 |
+
},
|
| 108 |
+
"id": "DCj_cP5xQ_lA",
|
| 109 |
+
"outputId": "493920ed-26b6-4dec-a3e0-7d8084698a7c"
|
| 110 |
+
},
|
| 111 |
+
"execution_count": null,
|
| 112 |
+
"outputs": [
|
| 113 |
+
{
|
| 114 |
+
"output_type": "stream",
|
| 115 |
+
"name": "stderr",
|
| 116 |
+
"text": [
|
| 117 |
+
"[nltk_data] Downloading package punkt_tab to /root/nltk_data...\n",
|
| 118 |
+
"[nltk_data] Package punkt_tab is already up-to-date!\n"
|
| 119 |
+
]
|
| 120 |
+
},
|
| 121 |
+
{
|
| 122 |
+
"output_type": "execute_result",
|
| 123 |
+
"data": {
|
| 124 |
+
"text/plain": [
|
| 125 |
+
"True"
|
| 126 |
+
]
|
| 127 |
+
},
|
| 128 |
+
"metadata": {},
|
| 129 |
+
"execution_count": 5
|
| 130 |
+
}
|
| 131 |
+
]
|
| 132 |
+
},
|
| 133 |
+
{
|
| 134 |
+
"cell_type": "code",
|
| 135 |
+
"source": [
|
| 136 |
+
"\n",
|
| 137 |
+
"\n",
|
| 138 |
+
"stop_words = set(stopwords.words('english'))\n",
|
| 139 |
+
"lemmatizer = WordNetLemmatizer()\n",
|
| 140 |
+
"\n",
|
| 141 |
+
"def preprocess_text(text):\n",
|
| 142 |
+
" # 1. Lowercase\n",
|
| 143 |
+
" text = text.lower()\n",
|
| 144 |
+
"\n",
|
| 145 |
+
" # 2. Remove HTML tags\n",
|
| 146 |
+
" text = re.sub(r'<.*?>', '', text)\n",
|
| 147 |
+
"\n",
|
| 148 |
+
" # 3. Remove punctuation & numbers\n",
|
| 149 |
+
" text = re.sub(r'[^a-z\\s]', '', text)\n",
|
| 150 |
+
"\n",
|
| 151 |
+
" # 4. Tokenize\n",
|
| 152 |
+
" tokens = nltk.word_tokenize(text)\n",
|
| 153 |
+
"\n",
|
| 154 |
+
" # 5. Remove stopwords\n",
|
| 155 |
+
" tokens = [word for word in tokens if word not in stop_words]\n",
|
| 156 |
+
"\n",
|
| 157 |
+
" # 6. Lemmatization\n",
|
| 158 |
+
" tokens = [lemmatizer.lemmatize(word) for word in tokens]\n",
|
| 159 |
+
"\n",
|
| 160 |
+
" return \" \".join(tokens)\n",
|
| 161 |
+
"\n"
|
| 162 |
+
],
|
| 163 |
+
"metadata": {
|
| 164 |
+
"id": "zID5UONlP1ok"
|
| 165 |
+
},
|
| 166 |
+
"execution_count": null,
|
| 167 |
+
"outputs": []
|
| 168 |
+
},
|
| 169 |
+
{
|
| 170 |
+
"cell_type": "code",
|
| 171 |
+
"source": [
|
| 172 |
+
"df[\"cleaned_review\"] = df[\"review\"].apply(preprocess_text)\n",
|
| 173 |
+
"\n",
|
| 174 |
+
"\n",
|
| 175 |
+
"print(df[[\"review\", \"cleaned_review\", \"sentiment\"]].tail())"
|
| 176 |
+
],
|
| 177 |
+
"metadata": {
|
| 178 |
+
"id": "HDsRgcxuP1rS",
|
| 179 |
+
"colab": {
|
| 180 |
+
"base_uri": "https://localhost:8080/"
|
| 181 |
+
},
|
| 182 |
+
"outputId": "a30f30f1-6640-451b-8a46-247d488c9a68"
|
| 183 |
+
},
|
| 184 |
+
"execution_count": null,
|
| 185 |
+
"outputs": [
|
| 186 |
+
{
|
| 187 |
+
"output_type": "stream",
|
| 188 |
+
"name": "stdout",
|
| 189 |
+
"text": [
|
| 190 |
+
" review \\\n",
|
| 191 |
+
"49995 I thought this movie did a down right good job... \n",
|
| 192 |
+
"49996 Bad plot, bad dialogue, bad acting, idiotic di... \n",
|
| 193 |
+
"49997 I am a Catholic taught in parochial elementary... \n",
|
| 194 |
+
"49998 I'm going to have to disagree with the previou... \n",
|
| 195 |
+
"49999 No one expects the Star Trek movies to be high... \n",
|
| 196 |
+
"\n",
|
| 197 |
+
" cleaned_review sentiment \n",
|
| 198 |
+
"49995 thought movie right good job wasnt creative or... positive \n",
|
| 199 |
+
"49996 bad plot bad dialogue bad acting idiotic direc... negative \n",
|
| 200 |
+
"49997 catholic taught parochial elementary school nu... negative \n",
|
| 201 |
+
"49998 im going disagree previous comment side maltin... negative \n",
|
| 202 |
+
"49999 one expects star trek movie high art fan expec... negative \n"
|
| 203 |
+
]
|
| 204 |
+
}
|
| 205 |
+
]
|
| 206 |
+
},
|
| 207 |
+
{
|
| 208 |
+
"cell_type": "code",
|
| 209 |
+
"source": [
|
| 210 |
+
"!pip install transformers torch sentence-transformers\n"
|
| 211 |
+
],
|
| 212 |
+
"metadata": {
|
| 213 |
+
"id": "DUf6-RvRP1uL",
|
| 214 |
+
"colab": {
|
| 215 |
+
"base_uri": "https://localhost:8080/"
|
| 216 |
+
},
|
| 217 |
+
"outputId": "c4b4362f-8aad-43d8-ac0e-56f7d20c4140"
|
| 218 |
+
},
|
| 219 |
+
"execution_count": null,
|
| 220 |
+
"outputs": [
|
| 221 |
+
{
|
| 222 |
+
"output_type": "stream",
|
| 223 |
+
"name": "stdout",
|
| 224 |
+
"text": [
|
| 225 |
+
"Requirement already satisfied: transformers in /usr/local/lib/python3.12/dist-packages (4.56.2)\n",
|
| 226 |
+
"Requirement already satisfied: torch in /usr/local/lib/python3.12/dist-packages (2.8.0+cu126)\n",
|
| 227 |
+
"Requirement already satisfied: sentence-transformers in /usr/local/lib/python3.12/dist-packages (5.1.1)\n",
|
| 228 |
+
"Requirement already satisfied: filelock in /usr/local/lib/python3.12/dist-packages (from transformers) (3.19.1)\n",
|
| 229 |
+
"Requirement already satisfied: huggingface-hub<1.0,>=0.34.0 in /usr/local/lib/python3.12/dist-packages (from transformers) (0.35.0)\n",
|
| 230 |
+
"Requirement already satisfied: numpy>=1.17 in /usr/local/lib/python3.12/dist-packages (from transformers) (1.26.0)\n",
|
| 231 |
+
"Requirement already satisfied: packaging>=20.0 in /usr/local/lib/python3.12/dist-packages (from transformers) (25.0)\n",
|
| 232 |
+
"Requirement already satisfied: pyyaml>=5.1 in /usr/local/lib/python3.12/dist-packages (from transformers) (6.0.2)\n",
|
| 233 |
+
"Requirement already satisfied: regex!=2019.12.17 in /usr/local/lib/python3.12/dist-packages (from transformers) (2024.11.6)\n",
|
| 234 |
+
"Requirement already satisfied: requests in /usr/local/lib/python3.12/dist-packages (from transformers) (2.32.4)\n",
|
| 235 |
+
"Requirement already satisfied: tokenizers<=0.23.0,>=0.22.0 in /usr/local/lib/python3.12/dist-packages (from transformers) (0.22.0)\n",
|
| 236 |
+
"Requirement already satisfied: safetensors>=0.4.3 in /usr/local/lib/python3.12/dist-packages (from transformers) (0.6.2)\n",
|
| 237 |
+
"Requirement already satisfied: tqdm>=4.27 in /usr/local/lib/python3.12/dist-packages (from transformers) (4.67.1)\n",
|
| 238 |
+
"Requirement already satisfied: typing-extensions>=4.10.0 in /usr/local/lib/python3.12/dist-packages (from torch) (4.15.0)\n",
|
| 239 |
+
"Requirement already satisfied: setuptools in /usr/local/lib/python3.12/dist-packages (from torch) (75.2.0)\n",
|
| 240 |
+
"Requirement already satisfied: sympy>=1.13.3 in /usr/local/lib/python3.12/dist-packages (from torch) (1.13.3)\n",
|
| 241 |
+
"Requirement already satisfied: networkx in /usr/local/lib/python3.12/dist-packages (from torch) (3.5)\n",
|
| 242 |
+
"Requirement already satisfied: jinja2 in /usr/local/lib/python3.12/dist-packages (from torch) (3.1.6)\n",
|
| 243 |
+
"Requirement already satisfied: fsspec in /usr/local/lib/python3.12/dist-packages (from torch) (2025.3.0)\n",
|
| 244 |
+
"Requirement already satisfied: nvidia-cuda-nvrtc-cu12==12.6.77 in /usr/local/lib/python3.12/dist-packages (from torch) (12.6.77)\n",
|
| 245 |
+
"Requirement already satisfied: nvidia-cuda-runtime-cu12==12.6.77 in /usr/local/lib/python3.12/dist-packages (from torch) (12.6.77)\n",
|
| 246 |
+
"Requirement already satisfied: nvidia-cuda-cupti-cu12==12.6.80 in /usr/local/lib/python3.12/dist-packages (from torch) (12.6.80)\n",
|
| 247 |
+
"Requirement already satisfied: nvidia-cudnn-cu12==9.10.2.21 in /usr/local/lib/python3.12/dist-packages (from torch) (9.10.2.21)\n",
|
| 248 |
+
"Requirement already satisfied: nvidia-cublas-cu12==12.6.4.1 in /usr/local/lib/python3.12/dist-packages (from torch) (12.6.4.1)\n",
|
| 249 |
+
"Requirement already satisfied: nvidia-cufft-cu12==11.3.0.4 in /usr/local/lib/python3.12/dist-packages (from torch) (11.3.0.4)\n",
|
| 250 |
+
"Requirement already satisfied: nvidia-curand-cu12==10.3.7.77 in /usr/local/lib/python3.12/dist-packages (from torch) (10.3.7.77)\n",
|
| 251 |
+
"Requirement already satisfied: nvidia-cusolver-cu12==11.7.1.2 in /usr/local/lib/python3.12/dist-packages (from torch) (11.7.1.2)\n",
|
| 252 |
+
"Requirement already satisfied: nvidia-cusparse-cu12==12.5.4.2 in /usr/local/lib/python3.12/dist-packages (from torch) (12.5.4.2)\n",
|
| 253 |
+
"Requirement already satisfied: nvidia-cusparselt-cu12==0.7.1 in /usr/local/lib/python3.12/dist-packages (from torch) (0.7.1)\n",
|
| 254 |
+
"Requirement already satisfied: nvidia-nccl-cu12==2.27.3 in /usr/local/lib/python3.12/dist-packages (from torch) (2.27.3)\n",
|
| 255 |
+
"Requirement already satisfied: nvidia-nvtx-cu12==12.6.77 in /usr/local/lib/python3.12/dist-packages (from torch) (12.6.77)\n",
|
| 256 |
+
"Requirement already satisfied: nvidia-nvjitlink-cu12==12.6.85 in /usr/local/lib/python3.12/dist-packages (from torch) (12.6.85)\n",
|
| 257 |
+
"Requirement already satisfied: nvidia-cufile-cu12==1.11.1.6 in /usr/local/lib/python3.12/dist-packages (from torch) (1.11.1.6)\n",
|
| 258 |
+
"Requirement already satisfied: triton==3.4.0 in /usr/local/lib/python3.12/dist-packages (from torch) (3.4.0)\n",
|
| 259 |
+
"Requirement already satisfied: scikit-learn in /usr/local/lib/python3.12/dist-packages (from sentence-transformers) (1.6.1)\n",
|
| 260 |
+
"Requirement already satisfied: scipy in /usr/local/lib/python3.12/dist-packages (from sentence-transformers) (1.16.2)\n",
|
| 261 |
+
"Requirement already satisfied: Pillow in /usr/local/lib/python3.12/dist-packages (from sentence-transformers) (11.3.0)\n",
|
| 262 |
+
"Requirement already satisfied: hf-xet<2.0.0,>=1.1.3 in /usr/local/lib/python3.12/dist-packages (from huggingface-hub<1.0,>=0.34.0->transformers) (1.1.10)\n",
|
| 263 |
+
"Requirement already satisfied: mpmath<1.4,>=1.1.0 in /usr/local/lib/python3.12/dist-packages (from sympy>=1.13.3->torch) (1.3.0)\n",
|
| 264 |
+
"Requirement already satisfied: MarkupSafe>=2.0 in /usr/local/lib/python3.12/dist-packages (from jinja2->torch) (3.0.2)\n",
|
| 265 |
+
"Requirement already satisfied: charset_normalizer<4,>=2 in /usr/local/lib/python3.12/dist-packages (from requests->transformers) (3.4.3)\n",
|
| 266 |
+
"Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.12/dist-packages (from requests->transformers) (3.10)\n",
|
| 267 |
+
"Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.12/dist-packages (from requests->transformers) (2.5.0)\n",
|
| 268 |
+
"Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.12/dist-packages (from requests->transformers) (2025.8.3)\n",
|
| 269 |
+
"Requirement already satisfied: joblib>=1.2.0 in /usr/local/lib/python3.12/dist-packages (from scikit-learn->sentence-transformers) (1.5.2)\n",
|
| 270 |
+
"Requirement already satisfied: threadpoolctl>=3.1.0 in /usr/local/lib/python3.12/dist-packages (from scikit-learn->sentence-transformers) (3.6.0)\n"
|
| 271 |
+
]
|
| 272 |
+
}
|
| 273 |
+
]
|
| 274 |
+
},
|
| 275 |
+
{
|
| 276 |
+
"cell_type": "code",
|
| 277 |
+
"source": [],
|
| 278 |
+
"metadata": {
|
| 279 |
+
"id": "so6p265dWAfb"
|
| 280 |
+
},
|
| 281 |
+
"execution_count": null,
|
| 282 |
+
"outputs": []
|
| 283 |
+
},
|
| 284 |
+
{
|
| 285 |
+
"cell_type": "code",
|
| 286 |
+
"source": [],
|
| 287 |
+
"metadata": {
|
| 288 |
+
"id": "j7qu7HlyWAkb"
|
| 289 |
+
},
|
| 290 |
+
"execution_count": null,
|
| 291 |
+
"outputs": []
|
| 292 |
+
},
|
| 293 |
+
{
|
| 294 |
+
"cell_type": "code",
|
| 295 |
+
"source": [
|
| 296 |
+
"!pip install -U torch torchvision torchaudio\n",
|
| 297 |
+
"!pip install -U transformers sentence-transformers\n"
|
| 298 |
+
],
|
| 299 |
+
"metadata": {
|
| 300 |
+
"id": "kQkAlTaKP1w0",
|
| 301 |
+
"colab": {
|
| 302 |
+
"base_uri": "https://localhost:8080/"
|
| 303 |
+
},
|
| 304 |
+
"outputId": "77568f04-e205-4524-c838-c46042a317a2"
|
| 305 |
+
},
|
| 306 |
+
"execution_count": null,
|
| 307 |
+
"outputs": [
|
| 308 |
+
{
|
| 309 |
+
"output_type": "stream",
|
| 310 |
+
"name": "stdout",
|
| 311 |
+
"text": [
|
| 312 |
+
"Requirement already satisfied: torch in /usr/local/lib/python3.12/dist-packages (2.8.0+cu126)\n",
|
| 313 |
+
"Requirement already satisfied: torchvision in /usr/local/lib/python3.12/dist-packages (0.23.0+cu126)\n",
|
| 314 |
+
"Requirement already satisfied: torchaudio in /usr/local/lib/python3.12/dist-packages (2.8.0+cu126)\n",
|
| 315 |
+
"Requirement already satisfied: filelock in /usr/local/lib/python3.12/dist-packages (from torch) (3.19.1)\n",
|
| 316 |
+
"Requirement already satisfied: typing-extensions>=4.10.0 in /usr/local/lib/python3.12/dist-packages (from torch) (4.15.0)\n",
|
| 317 |
+
"Requirement already satisfied: setuptools in /usr/local/lib/python3.12/dist-packages (from torch) (75.2.0)\n",
|
| 318 |
+
"Requirement already satisfied: sympy>=1.13.3 in /usr/local/lib/python3.12/dist-packages (from torch) (1.13.3)\n",
|
| 319 |
+
"Requirement already satisfied: networkx in /usr/local/lib/python3.12/dist-packages (from torch) (3.5)\n",
|
| 320 |
+
"Requirement already satisfied: jinja2 in /usr/local/lib/python3.12/dist-packages (from torch) (3.1.6)\n",
|
| 321 |
+
"Requirement already satisfied: fsspec in /usr/local/lib/python3.12/dist-packages (from torch) (2025.3.0)\n",
|
| 322 |
+
"Requirement already satisfied: nvidia-cuda-nvrtc-cu12==12.6.77 in /usr/local/lib/python3.12/dist-packages (from torch) (12.6.77)\n",
|
| 323 |
+
"Requirement already satisfied: nvidia-cuda-runtime-cu12==12.6.77 in /usr/local/lib/python3.12/dist-packages (from torch) (12.6.77)\n",
|
| 324 |
+
"Requirement already satisfied: nvidia-cuda-cupti-cu12==12.6.80 in /usr/local/lib/python3.12/dist-packages (from torch) (12.6.80)\n",
|
| 325 |
+
"Requirement already satisfied: nvidia-cudnn-cu12==9.10.2.21 in /usr/local/lib/python3.12/dist-packages (from torch) (9.10.2.21)\n",
|
| 326 |
+
"Requirement already satisfied: nvidia-cublas-cu12==12.6.4.1 in /usr/local/lib/python3.12/dist-packages (from torch) (12.6.4.1)\n",
|
| 327 |
+
"Requirement already satisfied: nvidia-cufft-cu12==11.3.0.4 in /usr/local/lib/python3.12/dist-packages (from torch) (11.3.0.4)\n",
|
| 328 |
+
"Requirement already satisfied: nvidia-curand-cu12==10.3.7.77 in /usr/local/lib/python3.12/dist-packages (from torch) (10.3.7.77)\n",
|
| 329 |
+
"Requirement already satisfied: nvidia-cusolver-cu12==11.7.1.2 in /usr/local/lib/python3.12/dist-packages (from torch) (11.7.1.2)\n",
|
| 330 |
+
"Requirement already satisfied: nvidia-cusparse-cu12==12.5.4.2 in /usr/local/lib/python3.12/dist-packages (from torch) (12.5.4.2)\n",
|
| 331 |
+
"Requirement already satisfied: nvidia-cusparselt-cu12==0.7.1 in /usr/local/lib/python3.12/dist-packages (from torch) (0.7.1)\n",
|
| 332 |
+
"Requirement already satisfied: nvidia-nccl-cu12==2.27.3 in /usr/local/lib/python3.12/dist-packages (from torch) (2.27.3)\n",
|
| 333 |
+
"Requirement already satisfied: nvidia-nvtx-cu12==12.6.77 in /usr/local/lib/python3.12/dist-packages (from torch) (12.6.77)\n",
|
| 334 |
+
"Requirement already satisfied: nvidia-nvjitlink-cu12==12.6.85 in /usr/local/lib/python3.12/dist-packages (from torch) (12.6.85)\n",
|
| 335 |
+
"Requirement already satisfied: nvidia-cufile-cu12==1.11.1.6 in /usr/local/lib/python3.12/dist-packages (from torch) (1.11.1.6)\n",
|
| 336 |
+
"Requirement already satisfied: triton==3.4.0 in /usr/local/lib/python3.12/dist-packages (from torch) (3.4.0)\n",
|
| 337 |
+
"Requirement already satisfied: numpy in /usr/local/lib/python3.12/dist-packages (from torchvision) (1.26.0)\n",
|
| 338 |
+
"Requirement already satisfied: pillow!=8.3.*,>=5.3.0 in /usr/local/lib/python3.12/dist-packages (from torchvision) (11.3.0)\n",
|
| 339 |
+
"Requirement already satisfied: mpmath<1.4,>=1.1.0 in /usr/local/lib/python3.12/dist-packages (from sympy>=1.13.3->torch) (1.3.0)\n",
|
| 340 |
+
"Requirement already satisfied: MarkupSafe>=2.0 in /usr/local/lib/python3.12/dist-packages (from jinja2->torch) (3.0.2)\n",
|
| 341 |
+
"Requirement already satisfied: transformers in /usr/local/lib/python3.12/dist-packages (4.56.2)\n",
|
| 342 |
+
"Requirement already satisfied: sentence-transformers in /usr/local/lib/python3.12/dist-packages (5.1.1)\n",
|
| 343 |
+
"Requirement already satisfied: filelock in /usr/local/lib/python3.12/dist-packages (from transformers) (3.19.1)\n",
|
| 344 |
+
"Requirement already satisfied: huggingface-hub<1.0,>=0.34.0 in /usr/local/lib/python3.12/dist-packages (from transformers) (0.35.0)\n",
|
| 345 |
+
"Requirement already satisfied: numpy>=1.17 in /usr/local/lib/python3.12/dist-packages (from transformers) (1.26.0)\n",
|
| 346 |
+
"Requirement already satisfied: packaging>=20.0 in /usr/local/lib/python3.12/dist-packages (from transformers) (25.0)\n",
|
| 347 |
+
"Requirement already satisfied: pyyaml>=5.1 in /usr/local/lib/python3.12/dist-packages (from transformers) (6.0.2)\n",
|
| 348 |
+
"Requirement already satisfied: regex!=2019.12.17 in /usr/local/lib/python3.12/dist-packages (from transformers) (2024.11.6)\n",
|
| 349 |
+
"Requirement already satisfied: requests in /usr/local/lib/python3.12/dist-packages (from transformers) (2.32.4)\n",
|
| 350 |
+
"Requirement already satisfied: tokenizers<=0.23.0,>=0.22.0 in /usr/local/lib/python3.12/dist-packages (from transformers) (0.22.0)\n",
|
| 351 |
+
"Requirement already satisfied: safetensors>=0.4.3 in /usr/local/lib/python3.12/dist-packages (from transformers) (0.6.2)\n",
|
| 352 |
+
"Requirement already satisfied: tqdm>=4.27 in /usr/local/lib/python3.12/dist-packages (from transformers) (4.67.1)\n",
|
| 353 |
+
"Requirement already satisfied: torch>=1.11.0 in /usr/local/lib/python3.12/dist-packages (from sentence-transformers) (2.8.0+cu126)\n",
|
| 354 |
+
"Requirement already satisfied: scikit-learn in /usr/local/lib/python3.12/dist-packages (from sentence-transformers) (1.6.1)\n",
|
| 355 |
+
"Requirement already satisfied: scipy in /usr/local/lib/python3.12/dist-packages (from sentence-transformers) (1.16.2)\n",
|
| 356 |
+
"Requirement already satisfied: Pillow in /usr/local/lib/python3.12/dist-packages (from sentence-transformers) (11.3.0)\n",
|
| 357 |
+
"Requirement already satisfied: typing_extensions>=4.5.0 in /usr/local/lib/python3.12/dist-packages (from sentence-transformers) (4.15.0)\n",
|
| 358 |
+
"Requirement already satisfied: fsspec>=2023.5.0 in /usr/local/lib/python3.12/dist-packages (from huggingface-hub<1.0,>=0.34.0->transformers) (2025.3.0)\n",
|
| 359 |
+
"Requirement already satisfied: hf-xet<2.0.0,>=1.1.3 in /usr/local/lib/python3.12/dist-packages (from huggingface-hub<1.0,>=0.34.0->transformers) (1.1.10)\n",
|
| 360 |
+
"Requirement already satisfied: setuptools in /usr/local/lib/python3.12/dist-packages (from torch>=1.11.0->sentence-transformers) (75.2.0)\n",
|
| 361 |
+
"Requirement already satisfied: sympy>=1.13.3 in /usr/local/lib/python3.12/dist-packages (from torch>=1.11.0->sentence-transformers) (1.13.3)\n",
|
| 362 |
+
"Requirement already satisfied: networkx in /usr/local/lib/python3.12/dist-packages (from torch>=1.11.0->sentence-transformers) (3.5)\n",
|
| 363 |
+
"Requirement already satisfied: jinja2 in /usr/local/lib/python3.12/dist-packages (from torch>=1.11.0->sentence-transformers) (3.1.6)\n",
|
| 364 |
+
"Requirement already satisfied: nvidia-cuda-nvrtc-cu12==12.6.77 in /usr/local/lib/python3.12/dist-packages (from torch>=1.11.0->sentence-transformers) (12.6.77)\n",
|
| 365 |
+
"Requirement already satisfied: nvidia-cuda-runtime-cu12==12.6.77 in /usr/local/lib/python3.12/dist-packages (from torch>=1.11.0->sentence-transformers) (12.6.77)\n",
|
| 366 |
+
"Requirement already satisfied: nvidia-cuda-cupti-cu12==12.6.80 in /usr/local/lib/python3.12/dist-packages (from torch>=1.11.0->sentence-transformers) (12.6.80)\n",
|
| 367 |
+
"Requirement already satisfied: nvidia-cudnn-cu12==9.10.2.21 in /usr/local/lib/python3.12/dist-packages (from torch>=1.11.0->sentence-transformers) (9.10.2.21)\n",
|
| 368 |
+
"Requirement already satisfied: nvidia-cublas-cu12==12.6.4.1 in /usr/local/lib/python3.12/dist-packages (from torch>=1.11.0->sentence-transformers) (12.6.4.1)\n",
|
| 369 |
+
"Requirement already satisfied: nvidia-cufft-cu12==11.3.0.4 in /usr/local/lib/python3.12/dist-packages (from torch>=1.11.0->sentence-transformers) (11.3.0.4)\n",
|
| 370 |
+
"Requirement already satisfied: nvidia-curand-cu12==10.3.7.77 in /usr/local/lib/python3.12/dist-packages (from torch>=1.11.0->sentence-transformers) (10.3.7.77)\n",
|
| 371 |
+
"Requirement already satisfied: nvidia-cusolver-cu12==11.7.1.2 in /usr/local/lib/python3.12/dist-packages (from torch>=1.11.0->sentence-transformers) (11.7.1.2)\n",
|
| 372 |
+
"Requirement already satisfied: nvidia-cusparse-cu12==12.5.4.2 in /usr/local/lib/python3.12/dist-packages (from torch>=1.11.0->sentence-transformers) (12.5.4.2)\n",
|
| 373 |
+
"Requirement already satisfied: nvidia-cusparselt-cu12==0.7.1 in /usr/local/lib/python3.12/dist-packages (from torch>=1.11.0->sentence-transformers) (0.7.1)\n",
|
| 374 |
+
"Requirement already satisfied: nvidia-nccl-cu12==2.27.3 in /usr/local/lib/python3.12/dist-packages (from torch>=1.11.0->sentence-transformers) (2.27.3)\n",
|
| 375 |
+
"Requirement already satisfied: nvidia-nvtx-cu12==12.6.77 in /usr/local/lib/python3.12/dist-packages (from torch>=1.11.0->sentence-transformers) (12.6.77)\n",
|
| 376 |
+
"Requirement already satisfied: nvidia-nvjitlink-cu12==12.6.85 in /usr/local/lib/python3.12/dist-packages (from torch>=1.11.0->sentence-transformers) (12.6.85)\n",
|
| 377 |
+
"Requirement already satisfied: nvidia-cufile-cu12==1.11.1.6 in /usr/local/lib/python3.12/dist-packages (from torch>=1.11.0->sentence-transformers) (1.11.1.6)\n",
|
| 378 |
+
"Requirement already satisfied: triton==3.4.0 in /usr/local/lib/python3.12/dist-packages (from torch>=1.11.0->sentence-transformers) (3.4.0)\n",
|
| 379 |
+
"Requirement already satisfied: charset_normalizer<4,>=2 in /usr/local/lib/python3.12/dist-packages (from requests->transformers) (3.4.3)\n",
|
| 380 |
+
"Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.12/dist-packages (from requests->transformers) (3.10)\n",
|
| 381 |
+
"Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.12/dist-packages (from requests->transformers) (2.5.0)\n",
|
| 382 |
+
"Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.12/dist-packages (from requests->transformers) (2025.8.3)\n",
|
| 383 |
+
"Requirement already satisfied: joblib>=1.2.0 in /usr/local/lib/python3.12/dist-packages (from scikit-learn->sentence-transformers) (1.5.2)\n",
|
| 384 |
+
"Requirement already satisfied: threadpoolctl>=3.1.0 in /usr/local/lib/python3.12/dist-packages (from scikit-learn->sentence-transformers) (3.6.0)\n",
|
| 385 |
+
"Requirement already satisfied: mpmath<1.4,>=1.1.0 in /usr/local/lib/python3.12/dist-packages (from sympy>=1.13.3->torch>=1.11.0->sentence-transformers) (1.3.0)\n",
|
| 386 |
+
"Requirement already satisfied: MarkupSafe>=2.0 in /usr/local/lib/python3.12/dist-packages (from jinja2->torch>=1.11.0->sentence-transformers) (3.0.2)\n"
|
| 387 |
+
]
|
| 388 |
+
}
|
| 389 |
+
]
|
| 390 |
+
},
|
| 391 |
+
{
|
| 392 |
+
"cell_type": "code",
|
| 393 |
+
"source": [
|
| 394 |
+
"\n",
|
| 395 |
+
"from sklearn.feature_extraction.text import TfidfVectorizer"
|
| 396 |
+
],
|
| 397 |
+
"metadata": {
|
| 398 |
+
"id": "Ai71-ZR9jXUy"
|
| 399 |
+
},
|
| 400 |
+
"execution_count": null,
|
| 401 |
+
"outputs": []
|
| 402 |
+
},
|
| 403 |
+
{
|
| 404 |
+
"cell_type": "code",
|
| 405 |
+
"source": [
|
| 406 |
+
"\n",
|
| 407 |
+
"tfidf = TfidfVectorizer(max_features=5000)\n",
|
| 408 |
+
"X = tfidf.fit_transform(df[\"cleaned_review\"])\n",
|
| 409 |
+
"\n",
|
| 410 |
+
"y = df[\"sentiment\"].map({\"positive\": 1, \"negative\": 0}).values\n",
|
| 411 |
+
"print(X)"
|
| 412 |
+
],
|
| 413 |
+
"metadata": {
|
| 414 |
+
"id": "qrre8w1hP1zn",
|
| 415 |
+
"colab": {
|
| 416 |
+
"base_uri": "https://localhost:8080/"
|
| 417 |
+
},
|
| 418 |
+
"outputId": "7e36be98-44f0-4f69-efcb-9d38c6d7a5a8"
|
| 419 |
+
},
|
| 420 |
+
"execution_count": null,
|
| 421 |
+
"outputs": [
|
| 422 |
+
{
|
| 423 |
+
"output_type": "stream",
|
| 424 |
+
"name": "stdout",
|
| 425 |
+
"text": [
|
| 426 |
+
"<Compressed Sparse Row sparse matrix of dtype 'float64'\n",
|
| 427 |
+
"\twith 3894163 stored elements and shape (50000, 5000)>\n",
|
| 428 |
+
" Coords\tValues\n",
|
| 429 |
+
" (0, 3086)\t0.022306340769509683\n",
|
| 430 |
+
" (0, 3687)\t0.0716098594890523\n",
|
| 431 |
+
" (0, 2778)\t0.06997013472849029\n",
|
| 432 |
+
" (0, 4832)\t0.08220463762202762\n",
|
| 433 |
+
" (0, 3137)\t0.47260726598173247\n",
|
| 434 |
+
" (0, 1467)\t0.11279543497089747\n",
|
| 435 |
+
" (0, 4990)\t0.05792759900745007\n",
|
| 436 |
+
" (0, 2119)\t0.0884283468115394\n",
|
| 437 |
+
" (0, 3707)\t0.09072957775856476\n",
|
| 438 |
+
" (0, 1513)\t0.06118924586115793\n",
|
| 439 |
+
" (0, 1993)\t0.06126011378849219\n",
|
| 440 |
+
" (0, 1697)\t0.06827831217826244\n",
|
| 441 |
+
" (0, 4468)\t0.034484905907198556\n",
|
| 442 |
+
" (0, 4258)\t0.1771814513806625\n",
|
| 443 |
+
" (0, 543)\t0.09851073786514736\n",
|
| 444 |
+
" (0, 3831)\t0.03333634078441469\n",
|
| 445 |
+
" (0, 4763)\t0.25095990028835147\n",
|
| 446 |
+
" (0, 3914)\t0.04650048507467132\n",
|
| 447 |
+
" (0, 4938)\t0.05348789066286241\n",
|
| 448 |
+
" (0, 1883)\t0.07135314796729297\n",
|
| 449 |
+
" (0, 4610)\t0.07763035600809258\n",
|
| 450 |
+
" (0, 3975)\t0.15304406167950377\n",
|
| 451 |
+
" (0, 3451)\t0.06917492387135953\n",
|
| 452 |
+
" (0, 3456)\t0.08224792976382196\n",
|
| 453 |
+
" (0, 3583)\t0.08260003424873928\n",
|
| 454 |
+
" :\t:\n",
|
| 455 |
+
" (49999, 4949)\t0.09967306284736142\n",
|
| 456 |
+
" (49999, 1608)\t0.18895470226431363\n",
|
| 457 |
+
" (49999, 2146)\t0.0938134095848708\n",
|
| 458 |
+
" (49999, 4608)\t0.10421390262146894\n",
|
| 459 |
+
" (49999, 680)\t0.1210849951944911\n",
|
| 460 |
+
" (49999, 3818)\t0.1207533622254777\n",
|
| 461 |
+
" (49999, 2470)\t0.12550521294127479\n",
|
| 462 |
+
" (49999, 4670)\t0.11972754064045821\n",
|
| 463 |
+
" (49999, 2540)\t0.10566290485449034\n",
|
| 464 |
+
" (49999, 1538)\t0.12096018782971787\n",
|
| 465 |
+
" (49999, 303)\t0.13528867065174088\n",
|
| 466 |
+
" (49999, 2002)\t0.14117928521526385\n",
|
| 467 |
+
" (49999, 2225)\t0.12437816971606588\n",
|
| 468 |
+
" (49999, 2205)\t0.1883414548411176\n",
|
| 469 |
+
" (49999, 241)\t0.12037119185480823\n",
|
| 470 |
+
" (49999, 4588)\t0.1774967991895605\n",
|
| 471 |
+
" (49999, 2457)\t0.2041086873930473\n",
|
| 472 |
+
" (49999, 4154)\t0.2230098076678039\n",
|
| 473 |
+
" (49999, 3632)\t0.17275135778399867\n",
|
| 474 |
+
" (49999, 581)\t0.16361717948998034\n",
|
| 475 |
+
" (49999, 2995)\t0.1828212276262584\n",
|
| 476 |
+
" (49999, 684)\t0.14413194406724505\n",
|
| 477 |
+
" (49999, 1897)\t0.17552265388590801\n",
|
| 478 |
+
" (49999, 3630)\t0.16768695545427548\n",
|
| 479 |
+
" (49999, 2903)\t0.19720455104959872\n"
|
| 480 |
+
]
|
| 481 |
+
}
|
| 482 |
+
]
|
| 483 |
+
},
|
| 484 |
+
{
|
| 485 |
+
"cell_type": "code",
|
| 486 |
+
"source": [
|
| 487 |
+
"\n",
|
| 488 |
+
"from sklearn.feature_extraction.text import TfidfVectorizer\n"
|
| 489 |
+
],
|
| 490 |
+
"metadata": {
|
| 491 |
+
"id": "y0voh7wgYX5z"
|
| 492 |
+
},
|
| 493 |
+
"execution_count": null,
|
| 494 |
+
"outputs": []
|
| 495 |
+
},
|
| 496 |
+
{
|
| 497 |
+
"cell_type": "markdown",
|
| 498 |
+
"source": [
|
| 499 |
+
"**MODEL**"
|
| 500 |
+
],
|
| 501 |
+
"metadata": {
|
| 502 |
+
"id": "9ahaUAiOjaih"
|
| 503 |
+
}
|
| 504 |
+
},
|
| 505 |
+
{
|
| 506 |
+
"cell_type": "code",
|
| 507 |
+
"source": [
|
| 508 |
+
"from sklearn.model_selection import train_test_split\n",
|
| 509 |
+
"from sklearn.linear_model import LogisticRegression\n",
|
| 510 |
+
"from sklearn.metrics import accuracy_score, classification_report, confusion_matrix\n",
|
| 511 |
+
"\n",
|
| 512 |
+
"\n",
|
| 513 |
+
"\n"
|
| 514 |
+
],
|
| 515 |
+
"metadata": {
|
| 516 |
+
"id": "fDNAJ33YP12O"
|
| 517 |
+
},
|
| 518 |
+
"execution_count": null,
|
| 519 |
+
"outputs": []
|
| 520 |
+
},
|
| 521 |
+
{
|
| 522 |
+
"cell_type": "code",
|
| 523 |
+
"source": [
|
| 524 |
+
"\n",
|
| 525 |
+
"X_train, X_test, y_train, y_test = train_test_split(\n",
|
| 526 |
+
" X, y, test_size=0.2, random_state=42\n",
|
| 527 |
+
")\n"
|
| 528 |
+
],
|
| 529 |
+
"metadata": {
|
| 530 |
+
"id": "a_u6DHxwP15A"
|
| 531 |
+
},
|
| 532 |
+
"execution_count": null,
|
| 533 |
+
"outputs": []
|
| 534 |
+
},
|
| 535 |
+
{
|
| 536 |
+
"cell_type": "code",
|
| 537 |
+
"source": [
|
| 538 |
+
"\n",
|
| 539 |
+
"clf = LogisticRegression(max_iter=200)\n",
|
| 540 |
+
"\n",
|
| 541 |
+
"clf.fit(X_train, y_train)\n"
|
| 542 |
+
],
|
| 543 |
+
"metadata": {
|
| 544 |
+
"colab": {
|
| 545 |
+
"base_uri": "https://localhost:8080/",
|
| 546 |
+
"height": 80
|
| 547 |
+
},
|
| 548 |
+
"id": "rebafV7PZQa8",
|
| 549 |
+
"outputId": "1237907c-d30f-4e97-914f-b16a544a98bf"
|
| 550 |
+
},
|
| 551 |
+
"execution_count": null,
|
| 552 |
+
"outputs": [
|
| 553 |
+
{
|
| 554 |
+
"output_type": "execute_result",
|
| 555 |
+
"data": {
|
| 556 |
+
"text/plain": [
|
| 557 |
+
"LogisticRegression(max_iter=200)"
|
| 558 |
+
],
|
| 559 |
+
"text/html": [
|
| 560 |
+
"<style>#sk-container-id-1 {\n",
|
| 561 |
+
" /* Definition of color scheme common for light and dark mode */\n",
|
| 562 |
+
" --sklearn-color-text: #000;\n",
|
| 563 |
+
" --sklearn-color-text-muted: #666;\n",
|
| 564 |
+
" --sklearn-color-line: gray;\n",
|
| 565 |
+
" /* Definition of color scheme for unfitted estimators */\n",
|
| 566 |
+
" --sklearn-color-unfitted-level-0: #fff5e6;\n",
|
| 567 |
+
" --sklearn-color-unfitted-level-1: #f6e4d2;\n",
|
| 568 |
+
" --sklearn-color-unfitted-level-2: #ffe0b3;\n",
|
| 569 |
+
" --sklearn-color-unfitted-level-3: chocolate;\n",
|
| 570 |
+
" /* Definition of color scheme for fitted estimators */\n",
|
| 571 |
+
" --sklearn-color-fitted-level-0: #f0f8ff;\n",
|
| 572 |
+
" --sklearn-color-fitted-level-1: #d4ebff;\n",
|
| 573 |
+
" --sklearn-color-fitted-level-2: #b3dbfd;\n",
|
| 574 |
+
" --sklearn-color-fitted-level-3: cornflowerblue;\n",
|
| 575 |
+
"\n",
|
| 576 |
+
" /* Specific color for light theme */\n",
|
| 577 |
+
" --sklearn-color-text-on-default-background: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, black)));\n",
|
| 578 |
+
" --sklearn-color-background: var(--sg-background-color, var(--theme-background, var(--jp-layout-color0, white)));\n",
|
| 579 |
+
" --sklearn-color-border-box: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, black)));\n",
|
| 580 |
+
" --sklearn-color-icon: #696969;\n",
|
| 581 |
+
"\n",
|
| 582 |
+
" @media (prefers-color-scheme: dark) {\n",
|
| 583 |
+
" /* Redefinition of color scheme for dark theme */\n",
|
| 584 |
+
" --sklearn-color-text-on-default-background: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, white)));\n",
|
| 585 |
+
" --sklearn-color-background: var(--sg-background-color, var(--theme-background, var(--jp-layout-color0, #111)));\n",
|
| 586 |
+
" --sklearn-color-border-box: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, white)));\n",
|
| 587 |
+
" --sklearn-color-icon: #878787;\n",
|
| 588 |
+
" }\n",
|
| 589 |
+
"}\n",
|
| 590 |
+
"\n",
|
| 591 |
+
"#sk-container-id-1 {\n",
|
| 592 |
+
" color: var(--sklearn-color-text);\n",
|
| 593 |
+
"}\n",
|
| 594 |
+
"\n",
|
| 595 |
+
"#sk-container-id-1 pre {\n",
|
| 596 |
+
" padding: 0;\n",
|
| 597 |
+
"}\n",
|
| 598 |
+
"\n",
|
| 599 |
+
"#sk-container-id-1 input.sk-hidden--visually {\n",
|
| 600 |
+
" border: 0;\n",
|
| 601 |
+
" clip: rect(1px 1px 1px 1px);\n",
|
| 602 |
+
" clip: rect(1px, 1px, 1px, 1px);\n",
|
| 603 |
+
" height: 1px;\n",
|
| 604 |
+
" margin: -1px;\n",
|
| 605 |
+
" overflow: hidden;\n",
|
| 606 |
+
" padding: 0;\n",
|
| 607 |
+
" position: absolute;\n",
|
| 608 |
+
" width: 1px;\n",
|
| 609 |
+
"}\n",
|
| 610 |
+
"\n",
|
| 611 |
+
"#sk-container-id-1 div.sk-dashed-wrapped {\n",
|
| 612 |
+
" border: 1px dashed var(--sklearn-color-line);\n",
|
| 613 |
+
" margin: 0 0.4em 0.5em 0.4em;\n",
|
| 614 |
+
" box-sizing: border-box;\n",
|
| 615 |
+
" padding-bottom: 0.4em;\n",
|
| 616 |
+
" background-color: var(--sklearn-color-background);\n",
|
| 617 |
+
"}\n",
|
| 618 |
+
"\n",
|
| 619 |
+
"#sk-container-id-1 div.sk-container {\n",
|
| 620 |
+
" /* jupyter's `normalize.less` sets `[hidden] { display: none; }`\n",
|
| 621 |
+
" but bootstrap.min.css set `[hidden] { display: none !important; }`\n",
|
| 622 |
+
" so we also need the `!important` here to be able to override the\n",
|
| 623 |
+
" default hidden behavior on the sphinx rendered scikit-learn.org.\n",
|
| 624 |
+
" See: https://github.com/scikit-learn/scikit-learn/issues/21755 */\n",
|
| 625 |
+
" display: inline-block !important;\n",
|
| 626 |
+
" position: relative;\n",
|
| 627 |
+
"}\n",
|
| 628 |
+
"\n",
|
| 629 |
+
"#sk-container-id-1 div.sk-text-repr-fallback {\n",
|
| 630 |
+
" display: none;\n",
|
| 631 |
+
"}\n",
|
| 632 |
+
"\n",
|
| 633 |
+
"div.sk-parallel-item,\n",
|
| 634 |
+
"div.sk-serial,\n",
|
| 635 |
+
"div.sk-item {\n",
|
| 636 |
+
" /* draw centered vertical line to link estimators */\n",
|
| 637 |
+
" background-image: linear-gradient(var(--sklearn-color-text-on-default-background), var(--sklearn-color-text-on-default-background));\n",
|
| 638 |
+
" background-size: 2px 100%;\n",
|
| 639 |
+
" background-repeat: no-repeat;\n",
|
| 640 |
+
" background-position: center center;\n",
|
| 641 |
+
"}\n",
|
| 642 |
+
"\n",
|
| 643 |
+
"/* Parallel-specific style estimator block */\n",
|
| 644 |
+
"\n",
|
| 645 |
+
"#sk-container-id-1 div.sk-parallel-item::after {\n",
|
| 646 |
+
" content: \"\";\n",
|
| 647 |
+
" width: 100%;\n",
|
| 648 |
+
" border-bottom: 2px solid var(--sklearn-color-text-on-default-background);\n",
|
| 649 |
+
" flex-grow: 1;\n",
|
| 650 |
+
"}\n",
|
| 651 |
+
"\n",
|
| 652 |
+
"#sk-container-id-1 div.sk-parallel {\n",
|
| 653 |
+
" display: flex;\n",
|
| 654 |
+
" align-items: stretch;\n",
|
| 655 |
+
" justify-content: center;\n",
|
| 656 |
+
" background-color: var(--sklearn-color-background);\n",
|
| 657 |
+
" position: relative;\n",
|
| 658 |
+
"}\n",
|
| 659 |
+
"\n",
|
| 660 |
+
"#sk-container-id-1 div.sk-parallel-item {\n",
|
| 661 |
+
" display: flex;\n",
|
| 662 |
+
" flex-direction: column;\n",
|
| 663 |
+
"}\n",
|
| 664 |
+
"\n",
|
| 665 |
+
"#sk-container-id-1 div.sk-parallel-item:first-child::after {\n",
|
| 666 |
+
" align-self: flex-end;\n",
|
| 667 |
+
" width: 50%;\n",
|
| 668 |
+
"}\n",
|
| 669 |
+
"\n",
|
| 670 |
+
"#sk-container-id-1 div.sk-parallel-item:last-child::after {\n",
|
| 671 |
+
" align-self: flex-start;\n",
|
| 672 |
+
" width: 50%;\n",
|
| 673 |
+
"}\n",
|
| 674 |
+
"\n",
|
| 675 |
+
"#sk-container-id-1 div.sk-parallel-item:only-child::after {\n",
|
| 676 |
+
" width: 0;\n",
|
| 677 |
+
"}\n",
|
| 678 |
+
"\n",
|
| 679 |
+
"/* Serial-specific style estimator block */\n",
|
| 680 |
+
"\n",
|
| 681 |
+
"#sk-container-id-1 div.sk-serial {\n",
|
| 682 |
+
" display: flex;\n",
|
| 683 |
+
" flex-direction: column;\n",
|
| 684 |
+
" align-items: center;\n",
|
| 685 |
+
" background-color: var(--sklearn-color-background);\n",
|
| 686 |
+
" padding-right: 1em;\n",
|
| 687 |
+
" padding-left: 1em;\n",
|
| 688 |
+
"}\n",
|
| 689 |
+
"\n",
|
| 690 |
+
"\n",
|
| 691 |
+
"/* Toggleable style: style used for estimator/Pipeline/ColumnTransformer box that is\n",
|
| 692 |
+
"clickable and can be expanded/collapsed.\n",
|
| 693 |
+
"- Pipeline and ColumnTransformer use this feature and define the default style\n",
|
| 694 |
+
"- Estimators will overwrite some part of the style using the `sk-estimator` class\n",
|
| 695 |
+
"*/\n",
|
| 696 |
+
"\n",
|
| 697 |
+
"/* Pipeline and ColumnTransformer style (default) */\n",
|
| 698 |
+
"\n",
|
| 699 |
+
"#sk-container-id-1 div.sk-toggleable {\n",
|
| 700 |
+
" /* Default theme specific background. It is overwritten whether we have a\n",
|
| 701 |
+
" specific estimator or a Pipeline/ColumnTransformer */\n",
|
| 702 |
+
" background-color: var(--sklearn-color-background);\n",
|
| 703 |
+
"}\n",
|
| 704 |
+
"\n",
|
| 705 |
+
"/* Toggleable label */\n",
|
| 706 |
+
"#sk-container-id-1 label.sk-toggleable__label {\n",
|
| 707 |
+
" cursor: pointer;\n",
|
| 708 |
+
" display: flex;\n",
|
| 709 |
+
" width: 100%;\n",
|
| 710 |
+
" margin-bottom: 0;\n",
|
| 711 |
+
" padding: 0.5em;\n",
|
| 712 |
+
" box-sizing: border-box;\n",
|
| 713 |
+
" text-align: center;\n",
|
| 714 |
+
" align-items: start;\n",
|
| 715 |
+
" justify-content: space-between;\n",
|
| 716 |
+
" gap: 0.5em;\n",
|
| 717 |
+
"}\n",
|
| 718 |
+
"\n",
|
| 719 |
+
"#sk-container-id-1 label.sk-toggleable__label .caption {\n",
|
| 720 |
+
" font-size: 0.6rem;\n",
|
| 721 |
+
" font-weight: lighter;\n",
|
| 722 |
+
" color: var(--sklearn-color-text-muted);\n",
|
| 723 |
+
"}\n",
|
| 724 |
+
"\n",
|
| 725 |
+
"#sk-container-id-1 label.sk-toggleable__label-arrow:before {\n",
|
| 726 |
+
" /* Arrow on the left of the label */\n",
|
| 727 |
+
" content: \"▸\";\n",
|
| 728 |
+
" float: left;\n",
|
| 729 |
+
" margin-right: 0.25em;\n",
|
| 730 |
+
" color: var(--sklearn-color-icon);\n",
|
| 731 |
+
"}\n",
|
| 732 |
+
"\n",
|
| 733 |
+
"#sk-container-id-1 label.sk-toggleable__label-arrow:hover:before {\n",
|
| 734 |
+
" color: var(--sklearn-color-text);\n",
|
| 735 |
+
"}\n",
|
| 736 |
+
"\n",
|
| 737 |
+
"/* Toggleable content - dropdown */\n",
|
| 738 |
+
"\n",
|
| 739 |
+
"#sk-container-id-1 div.sk-toggleable__content {\n",
|
| 740 |
+
" max-height: 0;\n",
|
| 741 |
+
" max-width: 0;\n",
|
| 742 |
+
" overflow: hidden;\n",
|
| 743 |
+
" text-align: left;\n",
|
| 744 |
+
" /* unfitted */\n",
|
| 745 |
+
" background-color: var(--sklearn-color-unfitted-level-0);\n",
|
| 746 |
+
"}\n",
|
| 747 |
+
"\n",
|
| 748 |
+
"#sk-container-id-1 div.sk-toggleable__content.fitted {\n",
|
| 749 |
+
" /* fitted */\n",
|
| 750 |
+
" background-color: var(--sklearn-color-fitted-level-0);\n",
|
| 751 |
+
"}\n",
|
| 752 |
+
"\n",
|
| 753 |
+
"#sk-container-id-1 div.sk-toggleable__content pre {\n",
|
| 754 |
+
" margin: 0.2em;\n",
|
| 755 |
+
" border-radius: 0.25em;\n",
|
| 756 |
+
" color: var(--sklearn-color-text);\n",
|
| 757 |
+
" /* unfitted */\n",
|
| 758 |
+
" background-color: var(--sklearn-color-unfitted-level-0);\n",
|
| 759 |
+
"}\n",
|
| 760 |
+
"\n",
|
| 761 |
+
"#sk-container-id-1 div.sk-toggleable__content.fitted pre {\n",
|
| 762 |
+
" /* unfitted */\n",
|
| 763 |
+
" background-color: var(--sklearn-color-fitted-level-0);\n",
|
| 764 |
+
"}\n",
|
| 765 |
+
"\n",
|
| 766 |
+
"#sk-container-id-1 input.sk-toggleable__control:checked~div.sk-toggleable__content {\n",
|
| 767 |
+
" /* Expand drop-down */\n",
|
| 768 |
+
" max-height: 200px;\n",
|
| 769 |
+
" max-width: 100%;\n",
|
| 770 |
+
" overflow: auto;\n",
|
| 771 |
+
"}\n",
|
| 772 |
+
"\n",
|
| 773 |
+
"#sk-container-id-1 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {\n",
|
| 774 |
+
" content: \"▾\";\n",
|
| 775 |
+
"}\n",
|
| 776 |
+
"\n",
|
| 777 |
+
"/* Pipeline/ColumnTransformer-specific style */\n",
|
| 778 |
+
"\n",
|
| 779 |
+
"#sk-container-id-1 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
|
| 780 |
+
" color: var(--sklearn-color-text);\n",
|
| 781 |
+
" background-color: var(--sklearn-color-unfitted-level-2);\n",
|
| 782 |
+
"}\n",
|
| 783 |
+
"\n",
|
| 784 |
+
"#sk-container-id-1 div.sk-label.fitted input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
|
| 785 |
+
" background-color: var(--sklearn-color-fitted-level-2);\n",
|
| 786 |
+
"}\n",
|
| 787 |
+
"\n",
|
| 788 |
+
"/* Estimator-specific style */\n",
|
| 789 |
+
"\n",
|
| 790 |
+
"/* Colorize estimator box */\n",
|
| 791 |
+
"#sk-container-id-1 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
|
| 792 |
+
" /* unfitted */\n",
|
| 793 |
+
" background-color: var(--sklearn-color-unfitted-level-2);\n",
|
| 794 |
+
"}\n",
|
| 795 |
+
"\n",
|
| 796 |
+
"#sk-container-id-1 div.sk-estimator.fitted input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
|
| 797 |
+
" /* fitted */\n",
|
| 798 |
+
" background-color: var(--sklearn-color-fitted-level-2);\n",
|
| 799 |
+
"}\n",
|
| 800 |
+
"\n",
|
| 801 |
+
"#sk-container-id-1 div.sk-label label.sk-toggleable__label,\n",
|
| 802 |
+
"#sk-container-id-1 div.sk-label label {\n",
|
| 803 |
+
" /* The background is the default theme color */\n",
|
| 804 |
+
" color: var(--sklearn-color-text-on-default-background);\n",
|
| 805 |
+
"}\n",
|
| 806 |
+
"\n",
|
| 807 |
+
"/* On hover, darken the color of the background */\n",
|
| 808 |
+
"#sk-container-id-1 div.sk-label:hover label.sk-toggleable__label {\n",
|
| 809 |
+
" color: var(--sklearn-color-text);\n",
|
| 810 |
+
" background-color: var(--sklearn-color-unfitted-level-2);\n",
|
| 811 |
+
"}\n",
|
| 812 |
+
"\n",
|
| 813 |
+
"/* Label box, darken color on hover, fitted */\n",
|
| 814 |
+
"#sk-container-id-1 div.sk-label.fitted:hover label.sk-toggleable__label.fitted {\n",
|
| 815 |
+
" color: var(--sklearn-color-text);\n",
|
| 816 |
+
" background-color: var(--sklearn-color-fitted-level-2);\n",
|
| 817 |
+
"}\n",
|
| 818 |
+
"\n",
|
| 819 |
+
"/* Estimator label */\n",
|
| 820 |
+
"\n",
|
| 821 |
+
"#sk-container-id-1 div.sk-label label {\n",
|
| 822 |
+
" font-family: monospace;\n",
|
| 823 |
+
" font-weight: bold;\n",
|
| 824 |
+
" display: inline-block;\n",
|
| 825 |
+
" line-height: 1.2em;\n",
|
| 826 |
+
"}\n",
|
| 827 |
+
"\n",
|
| 828 |
+
"#sk-container-id-1 div.sk-label-container {\n",
|
| 829 |
+
" text-align: center;\n",
|
| 830 |
+
"}\n",
|
| 831 |
+
"\n",
|
| 832 |
+
"/* Estimator-specific */\n",
|
| 833 |
+
"#sk-container-id-1 div.sk-estimator {\n",
|
| 834 |
+
" font-family: monospace;\n",
|
| 835 |
+
" border: 1px dotted var(--sklearn-color-border-box);\n",
|
| 836 |
+
" border-radius: 0.25em;\n",
|
| 837 |
+
" box-sizing: border-box;\n",
|
| 838 |
+
" margin-bottom: 0.5em;\n",
|
| 839 |
+
" /* unfitted */\n",
|
| 840 |
+
" background-color: var(--sklearn-color-unfitted-level-0);\n",
|
| 841 |
+
"}\n",
|
| 842 |
+
"\n",
|
| 843 |
+
"#sk-container-id-1 div.sk-estimator.fitted {\n",
|
| 844 |
+
" /* fitted */\n",
|
| 845 |
+
" background-color: var(--sklearn-color-fitted-level-0);\n",
|
| 846 |
+
"}\n",
|
| 847 |
+
"\n",
|
| 848 |
+
"/* on hover */\n",
|
| 849 |
+
"#sk-container-id-1 div.sk-estimator:hover {\n",
|
| 850 |
+
" /* unfitted */\n",
|
| 851 |
+
" background-color: var(--sklearn-color-unfitted-level-2);\n",
|
| 852 |
+
"}\n",
|
| 853 |
+
"\n",
|
| 854 |
+
"#sk-container-id-1 div.sk-estimator.fitted:hover {\n",
|
| 855 |
+
" /* fitted */\n",
|
| 856 |
+
" background-color: var(--sklearn-color-fitted-level-2);\n",
|
| 857 |
+
"}\n",
|
| 858 |
+
"\n",
|
| 859 |
+
"/* Specification for estimator info (e.g. \"i\" and \"?\") */\n",
|
| 860 |
+
"\n",
|
| 861 |
+
"/* Common style for \"i\" and \"?\" */\n",
|
| 862 |
+
"\n",
|
| 863 |
+
".sk-estimator-doc-link,\n",
|
| 864 |
+
"a:link.sk-estimator-doc-link,\n",
|
| 865 |
+
"a:visited.sk-estimator-doc-link {\n",
|
| 866 |
+
" float: right;\n",
|
| 867 |
+
" font-size: smaller;\n",
|
| 868 |
+
" line-height: 1em;\n",
|
| 869 |
+
" font-family: monospace;\n",
|
| 870 |
+
" background-color: var(--sklearn-color-background);\n",
|
| 871 |
+
" border-radius: 1em;\n",
|
| 872 |
+
" height: 1em;\n",
|
| 873 |
+
" width: 1em;\n",
|
| 874 |
+
" text-decoration: none !important;\n",
|
| 875 |
+
" margin-left: 0.5em;\n",
|
| 876 |
+
" text-align: center;\n",
|
| 877 |
+
" /* unfitted */\n",
|
| 878 |
+
" border: var(--sklearn-color-unfitted-level-1) 1pt solid;\n",
|
| 879 |
+
" color: var(--sklearn-color-unfitted-level-1);\n",
|
| 880 |
+
"}\n",
|
| 881 |
+
"\n",
|
| 882 |
+
".sk-estimator-doc-link.fitted,\n",
|
| 883 |
+
"a:link.sk-estimator-doc-link.fitted,\n",
|
| 884 |
+
"a:visited.sk-estimator-doc-link.fitted {\n",
|
| 885 |
+
" /* fitted */\n",
|
| 886 |
+
" border: var(--sklearn-color-fitted-level-1) 1pt solid;\n",
|
| 887 |
+
" color: var(--sklearn-color-fitted-level-1);\n",
|
| 888 |
+
"}\n",
|
| 889 |
+
"\n",
|
| 890 |
+
"/* On hover */\n",
|
| 891 |
+
"div.sk-estimator:hover .sk-estimator-doc-link:hover,\n",
|
| 892 |
+
".sk-estimator-doc-link:hover,\n",
|
| 893 |
+
"div.sk-label-container:hover .sk-estimator-doc-link:hover,\n",
|
| 894 |
+
".sk-estimator-doc-link:hover {\n",
|
| 895 |
+
" /* unfitted */\n",
|
| 896 |
+
" background-color: var(--sklearn-color-unfitted-level-3);\n",
|
| 897 |
+
" color: var(--sklearn-color-background);\n",
|
| 898 |
+
" text-decoration: none;\n",
|
| 899 |
+
"}\n",
|
| 900 |
+
"\n",
|
| 901 |
+
"div.sk-estimator.fitted:hover .sk-estimator-doc-link.fitted:hover,\n",
|
| 902 |
+
".sk-estimator-doc-link.fitted:hover,\n",
|
| 903 |
+
"div.sk-label-container:hover .sk-estimator-doc-link.fitted:hover,\n",
|
| 904 |
+
".sk-estimator-doc-link.fitted:hover {\n",
|
| 905 |
+
" /* fitted */\n",
|
| 906 |
+
" background-color: var(--sklearn-color-fitted-level-3);\n",
|
| 907 |
+
" color: var(--sklearn-color-background);\n",
|
| 908 |
+
" text-decoration: none;\n",
|
| 909 |
+
"}\n",
|
| 910 |
+
"\n",
|
| 911 |
+
"/* Span, style for the box shown on hovering the info icon */\n",
|
| 912 |
+
".sk-estimator-doc-link span {\n",
|
| 913 |
+
" display: none;\n",
|
| 914 |
+
" z-index: 9999;\n",
|
| 915 |
+
" position: relative;\n",
|
| 916 |
+
" font-weight: normal;\n",
|
| 917 |
+
" right: .2ex;\n",
|
| 918 |
+
" padding: .5ex;\n",
|
| 919 |
+
" margin: .5ex;\n",
|
| 920 |
+
" width: min-content;\n",
|
| 921 |
+
" min-width: 20ex;\n",
|
| 922 |
+
" max-width: 50ex;\n",
|
| 923 |
+
" color: var(--sklearn-color-text);\n",
|
| 924 |
+
" box-shadow: 2pt 2pt 4pt #999;\n",
|
| 925 |
+
" /* unfitted */\n",
|
| 926 |
+
" background: var(--sklearn-color-unfitted-level-0);\n",
|
| 927 |
+
" border: .5pt solid var(--sklearn-color-unfitted-level-3);\n",
|
| 928 |
+
"}\n",
|
| 929 |
+
"\n",
|
| 930 |
+
".sk-estimator-doc-link.fitted span {\n",
|
| 931 |
+
" /* fitted */\n",
|
| 932 |
+
" background: var(--sklearn-color-fitted-level-0);\n",
|
| 933 |
+
" border: var(--sklearn-color-fitted-level-3);\n",
|
| 934 |
+
"}\n",
|
| 935 |
+
"\n",
|
| 936 |
+
".sk-estimator-doc-link:hover span {\n",
|
| 937 |
+
" display: block;\n",
|
| 938 |
+
"}\n",
|
| 939 |
+
"\n",
|
| 940 |
+
"/* \"?\"-specific style due to the `<a>` HTML tag */\n",
|
| 941 |
+
"\n",
|
| 942 |
+
"#sk-container-id-1 a.estimator_doc_link {\n",
|
| 943 |
+
" float: right;\n",
|
| 944 |
+
" font-size: 1rem;\n",
|
| 945 |
+
" line-height: 1em;\n",
|
| 946 |
+
" font-family: monospace;\n",
|
| 947 |
+
" background-color: var(--sklearn-color-background);\n",
|
| 948 |
+
" border-radius: 1rem;\n",
|
| 949 |
+
" height: 1rem;\n",
|
| 950 |
+
" width: 1rem;\n",
|
| 951 |
+
" text-decoration: none;\n",
|
| 952 |
+
" /* unfitted */\n",
|
| 953 |
+
" color: var(--sklearn-color-unfitted-level-1);\n",
|
| 954 |
+
" border: var(--sklearn-color-unfitted-level-1) 1pt solid;\n",
|
| 955 |
+
"}\n",
|
| 956 |
+
"\n",
|
| 957 |
+
"#sk-container-id-1 a.estimator_doc_link.fitted {\n",
|
| 958 |
+
" /* fitted */\n",
|
| 959 |
+
" border: var(--sklearn-color-fitted-level-1) 1pt solid;\n",
|
| 960 |
+
" color: var(--sklearn-color-fitted-level-1);\n",
|
| 961 |
+
"}\n",
|
| 962 |
+
"\n",
|
| 963 |
+
"/* On hover */\n",
|
| 964 |
+
"#sk-container-id-1 a.estimator_doc_link:hover {\n",
|
| 965 |
+
" /* unfitted */\n",
|
| 966 |
+
" background-color: var(--sklearn-color-unfitted-level-3);\n",
|
| 967 |
+
" color: var(--sklearn-color-background);\n",
|
| 968 |
+
" text-decoration: none;\n",
|
| 969 |
+
"}\n",
|
| 970 |
+
"\n",
|
| 971 |
+
"#sk-container-id-1 a.estimator_doc_link.fitted:hover {\n",
|
| 972 |
+
" /* fitted */\n",
|
| 973 |
+
" background-color: var(--sklearn-color-fitted-level-3);\n",
|
| 974 |
+
"}\n",
|
| 975 |
+
"</style><div id=\"sk-container-id-1\" class=\"sk-top-container\"><div class=\"sk-text-repr-fallback\"><pre>LogisticRegression(max_iter=200)</pre><b>In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. <br />On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.</b></div><div class=\"sk-container\" hidden><div class=\"sk-item\"><div class=\"sk-estimator fitted sk-toggleable\"><input class=\"sk-toggleable__control sk-hidden--visually\" id=\"sk-estimator-id-1\" type=\"checkbox\" checked><label for=\"sk-estimator-id-1\" class=\"sk-toggleable__label fitted sk-toggleable__label-arrow\"><div><div>LogisticRegression</div></div><div><a class=\"sk-estimator-doc-link fitted\" rel=\"noreferrer\" target=\"_blank\" href=\"https://scikit-learn.org/1.6/modules/generated/sklearn.linear_model.LogisticRegression.html\">?<span>Documentation for LogisticRegression</span></a><span class=\"sk-estimator-doc-link fitted\">i<span>Fitted</span></span></div></label><div class=\"sk-toggleable__content fitted\"><pre>LogisticRegression(max_iter=200)</pre></div> </div></div></div></div>"
|
| 976 |
+
]
|
| 977 |
+
},
|
| 978 |
+
"metadata": {},
|
| 979 |
+
"execution_count": 15
|
| 980 |
+
}
|
| 981 |
+
]
|
| 982 |
+
},
|
| 983 |
+
{
|
| 984 |
+
"cell_type": "code",
|
| 985 |
+
"source": [
|
| 986 |
+
"y_pred = clf.predict(X_test)\n"
|
| 987 |
+
],
|
| 988 |
+
"metadata": {
|
| 989 |
+
"id": "zutBgt6SP17z"
|
| 990 |
+
},
|
| 991 |
+
"execution_count": null,
|
| 992 |
+
"outputs": []
|
| 993 |
+
},
|
| 994 |
+
{
|
| 995 |
+
"cell_type": "code",
|
| 996 |
+
"source": [
|
| 997 |
+
"\n",
|
| 998 |
+
"print(\"Accuracy:\", accuracy_score(y_test, y_pred))\n",
|
| 999 |
+
"\n",
|
| 1000 |
+
"\n",
|
| 1001 |
+
"print(classification_report(y_test, y_pred))\n",
|
| 1002 |
+
"\n",
|
| 1003 |
+
"\n",
|
| 1004 |
+
"print(\"Confusion Matrix:\\n\", confusion_matrix(y_test, y_pred))\n"
|
| 1005 |
+
],
|
| 1006 |
+
"metadata": {
|
| 1007 |
+
"id": "lOM-9luZP1-0",
|
| 1008 |
+
"colab": {
|
| 1009 |
+
"base_uri": "https://localhost:8080/"
|
| 1010 |
+
},
|
| 1011 |
+
"outputId": "c971b06d-e98b-494a-fcb2-8e11b31aa072"
|
| 1012 |
+
},
|
| 1013 |
+
"execution_count": null,
|
| 1014 |
+
"outputs": [
|
| 1015 |
+
{
|
| 1016 |
+
"output_type": "stream",
|
| 1017 |
+
"name": "stdout",
|
| 1018 |
+
"text": [
|
| 1019 |
+
"Accuracy: 0.8845\n",
|
| 1020 |
+
" precision recall f1-score support\n",
|
| 1021 |
+
"\n",
|
| 1022 |
+
" 0 0.89 0.87 0.88 4961\n",
|
| 1023 |
+
" 1 0.88 0.90 0.89 5039\n",
|
| 1024 |
+
"\n",
|
| 1025 |
+
" accuracy 0.88 10000\n",
|
| 1026 |
+
" macro avg 0.88 0.88 0.88 10000\n",
|
| 1027 |
+
"weighted avg 0.88 0.88 0.88 10000\n",
|
| 1028 |
+
"\n",
|
| 1029 |
+
"Confusion Matrix:\n",
|
| 1030 |
+
" [[4318 643]\n",
|
| 1031 |
+
" [ 512 4527]]\n"
|
| 1032 |
+
]
|
| 1033 |
+
}
|
| 1034 |
+
]
|
| 1035 |
+
},
|
| 1036 |
+
{
|
| 1037 |
+
"cell_type": "code",
|
| 1038 |
+
"source": [
|
| 1039 |
+
"# Uninstall conflicting packages\n",
|
| 1040 |
+
"!pip uninstall -y shap scipy\n",
|
| 1041 |
+
"\n",
|
| 1042 |
+
"# Install compatible versions\n",
|
| 1043 |
+
"!pip install scipy==1.10.1\n",
|
| 1044 |
+
"!pip install shap==0.42.1"
|
| 1045 |
+
],
|
| 1046 |
+
"metadata": {
|
| 1047 |
+
"colab": {
|
| 1048 |
+
"base_uri": "https://localhost:8080/",
|
| 1049 |
+
"height": 714
|
| 1050 |
+
},
|
| 1051 |
+
"id": "9FmYRCyOtS2L",
|
| 1052 |
+
"outputId": "5742d3ba-5692-4b0c-9bb8-6b83b49f77be"
|
| 1053 |
+
},
|
| 1054 |
+
"execution_count": null,
|
| 1055 |
+
"outputs": [
|
| 1056 |
+
{
|
| 1057 |
+
"output_type": "stream",
|
| 1058 |
+
"name": "stdout",
|
| 1059 |
+
"text": [
|
| 1060 |
+
"Found existing installation: shap 0.42.1\n",
|
| 1061 |
+
"Uninstalling shap-0.42.1:\n",
|
| 1062 |
+
" Successfully uninstalled shap-0.42.1\n",
|
| 1063 |
+
"Found existing installation: scipy 1.16.2\n",
|
| 1064 |
+
"Uninstalling scipy-1.16.2:\n",
|
| 1065 |
+
" Successfully uninstalled scipy-1.16.2\n",
|
| 1066 |
+
"\u001b[31mERROR: Ignored the following yanked versions: 1.11.0, 1.14.0rc1\u001b[0m\u001b[31m\n",
|
| 1067 |
+
"\u001b[0m\u001b[31mERROR: Ignored the following versions that require a different python version: 1.10.0 Requires-Python <3.12,>=3.8; 1.10.0rc1 Requires-Python <3.12,>=3.8; 1.10.0rc2 Requires-Python <3.12,>=3.8; 1.10.1 Requires-Python <3.12,>=3.8; 1.6.2 Requires-Python >=3.7,<3.10; 1.6.3 Requires-Python >=3.7,<3.10; 1.7.0 Requires-Python >=3.7,<3.10; 1.7.1 Requires-Python >=3.7,<3.10; 1.7.2 Requires-Python >=3.7,<3.11; 1.7.3 Requires-Python >=3.7,<3.11; 1.8.0 Requires-Python >=3.8,<3.11; 1.8.0rc1 Requires-Python >=3.8,<3.11; 1.8.0rc2 Requires-Python >=3.8,<3.11; 1.8.0rc3 Requires-Python >=3.8,<3.11; 1.8.0rc4 Requires-Python >=3.8,<3.11; 1.8.1 Requires-Python >=3.8,<3.11; 1.9.0 Requires-Python >=3.8,<3.12; 1.9.0rc1 Requires-Python >=3.8,<3.12; 1.9.0rc2 Requires-Python >=3.8,<3.12; 1.9.0rc3 Requires-Python >=3.8,<3.12; 1.9.1 Requires-Python >=3.8,<3.12\u001b[0m\u001b[31m\n",
|
| 1068 |
+
"\u001b[0m\u001b[31mERROR: Could not find a version that satisfies the requirement scipy==1.10.1 (from versions: 0.8.0, 0.9.0, 0.10.0, 0.10.1, 0.11.0, 0.12.0, 0.12.1, 0.13.0, 0.13.1, 0.13.2, 0.13.3, 0.14.0, 0.14.1, 0.15.0, 0.15.1, 0.16.0, 0.16.1, 0.17.0, 0.17.1, 0.18.0, 0.18.1, 0.19.0, 0.19.1, 1.0.0, 1.0.1, 1.1.0, 1.2.0, 1.2.1, 1.2.2, 1.2.3, 1.3.0, 1.3.1, 1.3.2, 1.3.3, 1.4.0, 1.4.1, 1.5.0, 1.5.1, 1.5.2, 1.5.3, 1.5.4, 1.6.0, 1.6.1, 1.9.2, 1.9.3, 1.11.0rc1, 1.11.0rc2, 1.11.1, 1.11.2, 1.11.3, 1.11.4, 1.12.0rc1, 1.12.0rc2, 1.12.0, 1.13.0rc1, 1.13.0, 1.13.1, 1.14.0rc2, 1.14.0, 1.14.1, 1.15.0rc1, 1.15.0rc2, 1.15.0, 1.15.1, 1.15.2, 1.15.3, 1.16.0rc1, 1.16.0rc2, 1.16.0, 1.16.1, 1.16.2)\u001b[0m\u001b[31m\n",
|
| 1069 |
+
"\u001b[0m\u001b[31mERROR: No matching distribution found for scipy==1.10.1\u001b[0m\u001b[31m\n",
|
| 1070 |
+
"\u001b[0mCollecting shap==0.42.1\n",
|
| 1071 |
+
" Using cached shap-0.42.1-cp312-cp312-linux_x86_64.whl\n",
|
| 1072 |
+
"Requirement already satisfied: numpy in /usr/local/lib/python3.12/dist-packages (from shap==0.42.1) (1.26.0)\n",
|
| 1073 |
+
"Collecting scipy (from shap==0.42.1)\n",
|
| 1074 |
+
" Using cached scipy-1.16.2-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.metadata (62 kB)\n",
|
| 1075 |
+
"Requirement already satisfied: scikit-learn in /usr/local/lib/python3.12/dist-packages (from shap==0.42.1) (1.6.1)\n",
|
| 1076 |
+
"Requirement already satisfied: pandas in /usr/local/lib/python3.12/dist-packages (from shap==0.42.1) (2.2.2)\n",
|
| 1077 |
+
"Requirement already satisfied: tqdm>=4.27.0 in /usr/local/lib/python3.12/dist-packages (from shap==0.42.1) (4.67.1)\n",
|
| 1078 |
+
"Requirement already satisfied: packaging>20.9 in /usr/local/lib/python3.12/dist-packages (from shap==0.42.1) (25.0)\n",
|
| 1079 |
+
"Requirement already satisfied: slicer==0.0.7 in /usr/local/lib/python3.12/dist-packages (from shap==0.42.1) (0.0.7)\n",
|
| 1080 |
+
"Requirement already satisfied: numba in /usr/local/lib/python3.12/dist-packages (from shap==0.42.1) (0.60.0)\n",
|
| 1081 |
+
"Requirement already satisfied: cloudpickle in /usr/local/lib/python3.12/dist-packages (from shap==0.42.1) (3.1.1)\n",
|
| 1082 |
+
"Requirement already satisfied: llvmlite<0.44,>=0.43.0dev0 in /usr/local/lib/python3.12/dist-packages (from numba->shap==0.42.1) (0.43.0)\n",
|
| 1083 |
+
"Requirement already satisfied: python-dateutil>=2.8.2 in /usr/local/lib/python3.12/dist-packages (from pandas->shap==0.42.1) (2.9.0.post0)\n",
|
| 1084 |
+
"Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.12/dist-packages (from pandas->shap==0.42.1) (2025.2)\n",
|
| 1085 |
+
"Requirement already satisfied: tzdata>=2022.7 in /usr/local/lib/python3.12/dist-packages (from pandas->shap==0.42.1) (2025.2)\n",
|
| 1086 |
+
"Requirement already satisfied: joblib>=1.2.0 in /usr/local/lib/python3.12/dist-packages (from scikit-learn->shap==0.42.1) (1.5.2)\n",
|
| 1087 |
+
"Requirement already satisfied: threadpoolctl>=3.1.0 in /usr/local/lib/python3.12/dist-packages (from scikit-learn->shap==0.42.1) (3.6.0)\n",
|
| 1088 |
+
"Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.12/dist-packages (from python-dateutil>=2.8.2->pandas->shap==0.42.1) (1.17.0)\n",
|
| 1089 |
+
"Using cached scipy-1.16.2-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (35.7 MB)\n",
|
| 1090 |
+
"Installing collected packages: scipy, shap\n",
|
| 1091 |
+
"Successfully installed scipy-1.16.2 shap-0.42.1\n"
|
| 1092 |
+
]
|
| 1093 |
+
},
|
| 1094 |
+
{
|
| 1095 |
+
"output_type": "display_data",
|
| 1096 |
+
"data": {
|
| 1097 |
+
"application/vnd.colab-display-data+json": {
|
| 1098 |
+
"pip_warning": {
|
| 1099 |
+
"packages": [
|
| 1100 |
+
"scipy",
|
| 1101 |
+
"shap"
|
| 1102 |
+
]
|
| 1103 |
+
},
|
| 1104 |
+
"id": "471ee32ea4224e2c8848bbf1936661d7"
|
| 1105 |
+
}
|
| 1106 |
+
},
|
| 1107 |
+
"metadata": {}
|
| 1108 |
+
}
|
| 1109 |
+
]
|
| 1110 |
+
},
|
| 1111 |
+
{
|
| 1112 |
+
"cell_type": "code",
|
| 1113 |
+
"source": [
|
| 1114 |
+
"!pip install numpy==1.26.0 shap==0.42.1\n",
|
| 1115 |
+
"\n"
|
| 1116 |
+
],
|
| 1117 |
+
"metadata": {
|
| 1118 |
+
"colab": {
|
| 1119 |
+
"base_uri": "https://localhost:8080/"
|
| 1120 |
+
},
|
| 1121 |
+
"id": "sgslFrBzuj2j",
|
| 1122 |
+
"outputId": "c013ef49-d02a-46ed-e28f-a669fe4ad0db"
|
| 1123 |
+
},
|
| 1124 |
+
"execution_count": null,
|
| 1125 |
+
"outputs": [
|
| 1126 |
+
{
|
| 1127 |
+
"output_type": "stream",
|
| 1128 |
+
"name": "stdout",
|
| 1129 |
+
"text": [
|
| 1130 |
+
"Requirement already satisfied: numpy==1.26.0 in /usr/local/lib/python3.12/dist-packages (1.26.0)\n",
|
| 1131 |
+
"Requirement already satisfied: shap==0.42.1 in /usr/local/lib/python3.12/dist-packages (0.42.1)\n",
|
| 1132 |
+
"Requirement already satisfied: scipy in /usr/local/lib/python3.12/dist-packages (from shap==0.42.1) (1.16.2)\n",
|
| 1133 |
+
"Requirement already satisfied: scikit-learn in /usr/local/lib/python3.12/dist-packages (from shap==0.42.1) (1.6.1)\n",
|
| 1134 |
+
"Requirement already satisfied: pandas in /usr/local/lib/python3.12/dist-packages (from shap==0.42.1) (2.2.2)\n",
|
| 1135 |
+
"Requirement already satisfied: tqdm>=4.27.0 in /usr/local/lib/python3.12/dist-packages (from shap==0.42.1) (4.67.1)\n",
|
| 1136 |
+
"Requirement already satisfied: packaging>20.9 in /usr/local/lib/python3.12/dist-packages (from shap==0.42.1) (25.0)\n",
|
| 1137 |
+
"Requirement already satisfied: slicer==0.0.7 in /usr/local/lib/python3.12/dist-packages (from shap==0.42.1) (0.0.7)\n",
|
| 1138 |
+
"Requirement already satisfied: numba in /usr/local/lib/python3.12/dist-packages (from shap==0.42.1) (0.60.0)\n",
|
| 1139 |
+
"Requirement already satisfied: cloudpickle in /usr/local/lib/python3.12/dist-packages (from shap==0.42.1) (3.1.1)\n",
|
| 1140 |
+
"Requirement already satisfied: llvmlite<0.44,>=0.43.0dev0 in /usr/local/lib/python3.12/dist-packages (from numba->shap==0.42.1) (0.43.0)\n",
|
| 1141 |
+
"Requirement already satisfied: python-dateutil>=2.8.2 in /usr/local/lib/python3.12/dist-packages (from pandas->shap==0.42.1) (2.9.0.post0)\n",
|
| 1142 |
+
"Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.12/dist-packages (from pandas->shap==0.42.1) (2025.2)\n",
|
| 1143 |
+
"Requirement already satisfied: tzdata>=2022.7 in /usr/local/lib/python3.12/dist-packages (from pandas->shap==0.42.1) (2025.2)\n",
|
| 1144 |
+
"Requirement already satisfied: joblib>=1.2.0 in /usr/local/lib/python3.12/dist-packages (from scikit-learn->shap==0.42.1) (1.5.2)\n",
|
| 1145 |
+
"Requirement already satisfied: threadpoolctl>=3.1.0 in /usr/local/lib/python3.12/dist-packages (from scikit-learn->shap==0.42.1) (3.6.0)\n",
|
| 1146 |
+
"Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.12/dist-packages (from python-dateutil>=2.8.2->pandas->shap==0.42.1) (1.17.0)\n"
|
| 1147 |
+
]
|
| 1148 |
+
}
|
| 1149 |
+
]
|
| 1150 |
+
},
|
| 1151 |
+
{
|
| 1152 |
+
"cell_type": "code",
|
| 1153 |
+
"source": [
|
| 1154 |
+
"import numpy as np\n",
|
| 1155 |
+
"\n",
|
| 1156 |
+
"\n",
|
| 1157 |
+
"np.obj2sctype = lambda obj: np.dtype(obj).type\n",
|
| 1158 |
+
"\n",
|
| 1159 |
+
"import shap\n"
|
| 1160 |
+
],
|
| 1161 |
+
"metadata": {
|
| 1162 |
+
"id": "ju0ZjEtXrzej"
|
| 1163 |
+
},
|
| 1164 |
+
"execution_count": null,
|
| 1165 |
+
"outputs": []
|
| 1166 |
+
},
|
| 1167 |
+
{
|
| 1168 |
+
"cell_type": "code",
|
| 1169 |
+
"source": [],
|
| 1170 |
+
"metadata": {
|
| 1171 |
+
"id": "2ng9Yfj-p3z4"
|
| 1172 |
+
},
|
| 1173 |
+
"execution_count": null,
|
| 1174 |
+
"outputs": []
|
| 1175 |
+
},
|
| 1176 |
+
{
|
| 1177 |
+
"cell_type": "code",
|
| 1178 |
+
"source": [],
|
| 1179 |
+
"metadata": {
|
| 1180 |
+
"id": "_ffFRvF8oy1l"
|
| 1181 |
+
},
|
| 1182 |
+
"execution_count": null,
|
| 1183 |
+
"outputs": []
|
| 1184 |
+
},
|
| 1185 |
+
{
|
| 1186 |
+
"cell_type": "markdown",
|
| 1187 |
+
"source": [
|
| 1188 |
+
"MODEL 2\n"
|
| 1189 |
+
],
|
| 1190 |
+
"metadata": {
|
| 1191 |
+
"id": "iD0gMTx-jfP4"
|
| 1192 |
+
}
|
| 1193 |
+
},
|
| 1194 |
+
{
|
| 1195 |
+
"cell_type": "code",
|
| 1196 |
+
"source": [
|
| 1197 |
+
"\n",
|
| 1198 |
+
"\n",
|
| 1199 |
+
"from sklearn.model_selection import train_test_split\n",
|
| 1200 |
+
"from tensorflow.keras.preprocessing.text import Tokenizer\n",
|
| 1201 |
+
"from tensorflow.keras.preprocessing.sequence import pad_sequences\n",
|
| 1202 |
+
"from tensorflow.keras.models import Sequential\n",
|
| 1203 |
+
"from tensorflow.keras.layers import Embedding, LSTM, Dense, Dropout, Bidirectional\n",
|
| 1204 |
+
"\n",
|
| 1205 |
+
"max_words = 10000\n",
|
| 1206 |
+
"max_len = 200\n",
|
| 1207 |
+
"\n",
|
| 1208 |
+
"tokenizer = Tokenizer(num_words=max_words)\n",
|
| 1209 |
+
"tokenizer.fit_on_texts(df[\"cleaned_review\"])\n",
|
| 1210 |
+
"sequences = tokenizer.texts_to_sequences(df[\"cleaned_review\"])\n",
|
| 1211 |
+
"X = pad_sequences(sequences, maxlen=max_len)\n",
|
| 1212 |
+
"\n",
|
| 1213 |
+
"y = df[\"sentiment\"].map({\"positive\": 1, \"negative\": 0}).values\n",
|
| 1214 |
+
"\n",
|
| 1215 |
+
"\n",
|
| 1216 |
+
"X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)\n",
|
| 1217 |
+
"\n",
|
| 1218 |
+
"\n",
|
| 1219 |
+
"model = Sequential()\n",
|
| 1220 |
+
"model.add(Embedding(input_dim=max_words, output_dim=128, input_length=max_len))\n",
|
| 1221 |
+
"model.add(Bidirectional(LSTM(64)))\n",
|
| 1222 |
+
"model.add(Dropout(0.5))\n",
|
| 1223 |
+
"model.add(Dense(1, activation='sigmoid'))\n",
|
| 1224 |
+
"\n",
|
| 1225 |
+
"model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])\n",
|
| 1226 |
+
"model.summary()\n",
|
| 1227 |
+
"\n",
|
| 1228 |
+
"\n",
|
| 1229 |
+
"history = model.fit(\n",
|
| 1230 |
+
" X_train, y_train,\n",
|
| 1231 |
+
" epochs=5,\n",
|
| 1232 |
+
" batch_size=128,\n",
|
| 1233 |
+
" validation_split=0.1\n",
|
| 1234 |
+
")\n",
|
| 1235 |
+
"\n",
|
| 1236 |
+
"\n",
|
| 1237 |
+
"\n",
|
| 1238 |
+
"loss, accuracy = model.evaluate(X_test, y_test)\n",
|
| 1239 |
+
"print(\"LSTM Test Accuracy:\", accuracy)\n",
|
| 1240 |
+
"\n",
|
| 1241 |
+
"\n"
|
| 1242 |
+
],
|
| 1243 |
+
"metadata": {
|
| 1244 |
+
"id": "ZX3VcwlOP2EK"
|
| 1245 |
+
},
|
| 1246 |
+
"execution_count": null,
|
| 1247 |
+
"outputs": []
|
| 1248 |
+
},
|
| 1249 |
+
{
|
| 1250 |
+
"cell_type": "code",
|
| 1251 |
+
"source": [
|
| 1252 |
+
"\n",
|
| 1253 |
+
"!pip uninstall -y shap scipy\n",
|
| 1254 |
+
"\n",
|
| 1255 |
+
"\n",
|
| 1256 |
+
"!pip install scipy==1.10.1\n",
|
| 1257 |
+
"!pip install shap==0.42.1"
|
| 1258 |
+
],
|
| 1259 |
+
"metadata": {
|
| 1260 |
+
"id": "2_DekM_ijieI"
|
| 1261 |
+
},
|
| 1262 |
+
"execution_count": null,
|
| 1263 |
+
"outputs": []
|
| 1264 |
+
},
|
| 1265 |
+
{
|
| 1266 |
+
"cell_type": "code",
|
| 1267 |
+
"source": [],
|
| 1268 |
+
"metadata": {
|
| 1269 |
+
"id": "_Iwjp2JpjihN"
|
| 1270 |
+
},
|
| 1271 |
+
"execution_count": null,
|
| 1272 |
+
"outputs": []
|
| 1273 |
+
},
|
| 1274 |
+
{
|
| 1275 |
+
"cell_type": "code",
|
| 1276 |
+
"source": [],
|
| 1277 |
+
"metadata": {
|
| 1278 |
+
"id": "QlgbCNxUjikB"
|
| 1279 |
+
},
|
| 1280 |
+
"execution_count": null,
|
| 1281 |
+
"outputs": []
|
| 1282 |
+
},
|
| 1283 |
+
{
|
| 1284 |
+
"cell_type": "code",
|
| 1285 |
+
"source": [],
|
| 1286 |
+
"metadata": {
|
| 1287 |
+
"id": "afS4-CfWjinK"
|
| 1288 |
+
},
|
| 1289 |
+
"execution_count": null,
|
| 1290 |
+
"outputs": []
|
| 1291 |
+
},
|
| 1292 |
+
{
|
| 1293 |
+
"cell_type": "code",
|
| 1294 |
+
"source": [
|
| 1295 |
+
"import shap\n",
|
| 1296 |
+
"import numpy as np\n",
|
| 1297 |
+
"\n",
|
| 1298 |
+
"X_background = X_train[:100]\n",
|
| 1299 |
+
"\n",
|
| 1300 |
+
"explainer = shap.DeepExplainer(model, X_background)\n",
|
| 1301 |
+
"\n",
|
| 1302 |
+
"\n",
|
| 1303 |
+
"sample_review = X_test[0:1]\n",
|
| 1304 |
+
"\n",
|
| 1305 |
+
"\n",
|
| 1306 |
+
"shap_values = explainer.shap_values(sample_review)\n",
|
| 1307 |
+
"\n",
|
| 1308 |
+
"\n",
|
| 1309 |
+
"index_word = {v: k for k, v in tokenizer.word_index.items()}\n",
|
| 1310 |
+
"words = [index_word.get(i, '') for i in sample_review[0] if i != 0]\n",
|
| 1311 |
+
"\n",
|
| 1312 |
+
"shap.initjs()\n",
|
| 1313 |
+
"shap.force_plot(explainer.expected_value[0], shap_values[0][0], words)\n"
|
| 1314 |
+
],
|
| 1315 |
+
"metadata": {
|
| 1316 |
+
"id": "D1zFJ5gwP2SC"
|
| 1317 |
+
},
|
| 1318 |
+
"execution_count": null,
|
| 1319 |
+
"outputs": []
|
| 1320 |
+
},
|
| 1321 |
+
{
|
| 1322 |
+
"cell_type": "code",
|
| 1323 |
+
"source": [
|
| 1324 |
+
"import shap"
|
| 1325 |
+
],
|
| 1326 |
+
"metadata": {
|
| 1327 |
+
"id": "vwQyqFNlhOc4"
|
| 1328 |
+
},
|
| 1329 |
+
"execution_count": null,
|
| 1330 |
+
"outputs": []
|
| 1331 |
+
},
|
| 1332 |
+
{
|
| 1333 |
+
"cell_type": "code",
|
| 1334 |
+
"source": [
|
| 1335 |
+
"Logistic Regression is a simple baseline model for sentiment analysis, using features like bag-of-words or TF-IDF but ignores word order. LSTM, on the other hand, is a deep learning model that captures sequence and context, making it more accurate for understanding movie reviews"
|
| 1336 |
+
],
|
| 1337 |
+
"metadata": {
|
| 1338 |
+
"id": "SReiT-0giWKR"
|
| 1339 |
+
},
|
| 1340 |
+
"execution_count": null,
|
| 1341 |
+
"outputs": []
|
| 1342 |
+
}
|
| 1343 |
+
],
|
| 1344 |
+
"metadata": {
|
| 1345 |
+
"colab": {
|
| 1346 |
+
"provenance": []
|
| 1347 |
+
},
|
| 1348 |
+
"kernelspec": {
|
| 1349 |
+
"display_name": "Python 3",
|
| 1350 |
+
"name": "python3"
|
| 1351 |
+
}
|
| 1352 |
+
},
|
| 1353 |
+
"nbformat": 4,
|
| 1354 |
+
"nbformat_minor": 0
|
| 1355 |
+
}
|