Team Ai
Apppublic

talib-ai-ml/Email-Classification

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
Notebook.ipynb665 linesDownload Raw Back to root
1{2 "cells": [3  {4   "cell_type": "code",5   "execution_count": 1,6   "id": "2276651d",7   "metadata": {},8   "outputs": [],9   "source": [10    "import pandas as pd\n",11    "import sklearn\n",12    "from sklearn.ensemble import RandomForestClassifier\n",13    "from sklearn.feature_extraction.text import TfidfVectorizer\n",14    "from sklearn.model_selection import train_test_split\n",15    "from sklearn.metrics import classification_report\n",16    "import pickle"17   ]18  },19  {20   "cell_type": "code",21   "execution_count": 2,22   "id": "4b0793a5",23   "metadata": {},24   "outputs": [25    {26     "name": "stdout",27     "output_type": "stream",28     "text": [29      "scikit-learn version: 1.6.1\n"30     ]31    }32   ],33   "source": [34    "print(\"scikit-learn version:\", sklearn.__version__)"35   ]36  },37  {38   "cell_type": "code",39   "execution_count": 3,40   "id": "2d0a267a",41   "metadata": {},42   "outputs": [43    {44     "data": {45      "text/html": [46       "<div>\n",47       "<style scoped>\n",48       "    .dataframe tbody tr th:only-of-type {\n",49       "        vertical-align: middle;\n",50       "    }\n",51       "\n",52       "    .dataframe tbody tr th {\n",53       "        vertical-align: top;\n",54       "    }\n",55       "\n",56       "    .dataframe thead th {\n",57       "        text-align: right;\n",58       "    }\n",59       "</style>\n",60       "<table border=\"1\" class=\"dataframe\">\n",61       "  <thead>\n",62       "    <tr style=\"text-align: right;\">\n",63       "      <th></th>\n",64       "      <th>email</th>\n",65       "      <th>type</th>\n",66       "    </tr>\n",67       "  </thead>\n",68       "  <tbody>\n",69       "    <tr>\n",70       "      <th>0</th>\n",71       "      <td>Subject: Unvorhergesehener Absturz der Datenan...</td>\n",72       "      <td>Incident</td>\n",73       "    </tr>\n",74       "    <tr>\n",75       "      <th>1</th>\n",76       "      <td>Subject: Customer Support Inquiry\\n\\nSeeking i...</td>\n",77       "      <td>Request</td>\n",78       "    </tr>\n",79       "    <tr>\n",80       "      <th>2</th>\n",81       "      <td>Subject: Data Analytics for Investment\\n\\nI am...</td>\n",82       "      <td>Request</td>\n",83       "    </tr>\n",84       "    <tr>\n",85       "      <th>3</th>\n",86       "      <td>Subject: Krankenhaus-Dienstleistung-Problem\\n\\...</td>\n",87       "      <td>Incident</td>\n",88       "    </tr>\n",89       "    <tr>\n",90       "      <th>4</th>\n",91       "      <td>Subject: Security\\n\\nDear Customer Support, I ...</td>\n",92       "      <td>Request</td>\n",93       "    </tr>\n",94       "  </tbody>\n",95       "</table>\n",96       "</div>"97      ],98      "text/plain": [99       "                                               email      type\n",100       "0  Subject: Unvorhergesehener Absturz der Datenan...  Incident\n",101       "1  Subject: Customer Support Inquiry\\n\\nSeeking i...   Request\n",102       "2  Subject: Data Analytics for Investment\\n\\nI am...   Request\n",103       "3  Subject: Krankenhaus-Dienstleistung-Problem\\n\\...  Incident\n",104       "4  Subject: Security\\n\\nDear Customer Support, I ...   Request"105      ]106     },107     "execution_count": 3,108     "metadata": {},109     "output_type": "execute_result"110    }111   ],112   "source": [113    "df = pd.read_csv(\"combined_emails_with_natural_pii.csv\")  # Replace with your actual dataset path\n",114    "\n",115    "# Check the first few rows of the dataset\n",116    "df.head()\n"117   ]118  },119  {120   "cell_type": "code",121   "execution_count": 4,122   "id": "8ed12426",123   "metadata": {},124   "outputs": [],125   "source": [126    "# Step 2: Preprocess and Vectorize the email text using TF-IDF\n",127    "vectorizer = TfidfVectorizer(stop_words=\"english\")\n",128    "X = vectorizer.fit_transform(df['email'])  # Email text as feature\n",129    "\n",130    "# Step 3: Define target labels (categories)\n",131    "y = df['type']  # Categories: 'Incident', 'Request', 'Problem', 'Change'\n"132   ]133  },134  {135   "cell_type": "code",136   "execution_count": 5,137   "id": "b72d2e8e",138   "metadata": {},139   "outputs": [],140   "source": [141    "# Step 4: Split the dataset into training and testing sets\n",142    "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42)\n"143   ]144  },145  {146   "cell_type": "code",147   "execution_count": 6,148   "id": "4f432786",149   "metadata": {},150   "outputs": [151    {152     "data": {153      "text/html": [154       "<style>#sk-container-id-1 {\n",155       "  /* Definition of color scheme common for light and dark mode */\n",156       "  --sklearn-color-text: #000;\n",157       "  --sklearn-color-text-muted: #666;\n",158       "  --sklearn-color-line: gray;\n",159       "  /* Definition of color scheme for unfitted estimators */\n",160       "  --sklearn-color-unfitted-level-0: #fff5e6;\n",161       "  --sklearn-color-unfitted-level-1: #f6e4d2;\n",162       "  --sklearn-color-unfitted-level-2: #ffe0b3;\n",163       "  --sklearn-color-unfitted-level-3: chocolate;\n",164       "  /* Definition of color scheme for fitted estimators */\n",165       "  --sklearn-color-fitted-level-0: #f0f8ff;\n",166       "  --sklearn-color-fitted-level-1: #d4ebff;\n",167       "  --sklearn-color-fitted-level-2: #b3dbfd;\n",168       "  --sklearn-color-fitted-level-3: cornflowerblue;\n",169       "\n",170       "  /* Specific color for light theme */\n",171       "  --sklearn-color-text-on-default-background: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, black)));\n",172       "  --sklearn-color-background: var(--sg-background-color, var(--theme-background, var(--jp-layout-color0, white)));\n",173       "  --sklearn-color-border-box: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, black)));\n",174       "  --sklearn-color-icon: #696969;\n",175       "\n",176       "  @media (prefers-color-scheme: dark) {\n",177       "    /* Redefinition of color scheme for dark theme */\n",178       "    --sklearn-color-text-on-default-background: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, white)));\n",179       "    --sklearn-color-background: var(--sg-background-color, var(--theme-background, var(--jp-layout-color0, #111)));\n",180       "    --sklearn-color-border-box: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, white)));\n",181       "    --sklearn-color-icon: #878787;\n",182       "  }\n",183       "}\n",184       "\n",185       "#sk-container-id-1 {\n",186       "  color: var(--sklearn-color-text);\n",187       "}\n",188       "\n",189       "#sk-container-id-1 pre {\n",190       "  padding: 0;\n",191       "}\n",192       "\n",193       "#sk-container-id-1 input.sk-hidden--visually {\n",194       "  border: 0;\n",195       "  clip: rect(1px 1px 1px 1px);\n",196       "  clip: rect(1px, 1px, 1px, 1px);\n",197       "  height: 1px;\n",198       "  margin: -1px;\n",199       "  overflow: hidden;\n",200       "  padding: 0;\n",201       "  position: absolute;\n",202       "  width: 1px;\n",203       "}\n",204       "\n",205       "#sk-container-id-1 div.sk-dashed-wrapped {\n",206       "  border: 1px dashed var(--sklearn-color-line);\n",207       "  margin: 0 0.4em 0.5em 0.4em;\n",208       "  box-sizing: border-box;\n",209       "  padding-bottom: 0.4em;\n",210       "  background-color: var(--sklearn-color-background);\n",211       "}\n",212       "\n",213       "#sk-container-id-1 div.sk-container {\n",214       "  /* jupyter's `normalize.less` sets `[hidden] { display: none; }`\n",215       "     but bootstrap.min.css set `[hidden] { display: none !important; }`\n",216       "     so we also need the `!important` here to be able to override the\n",217       "     default hidden behavior on the sphinx rendered scikit-learn.org.\n",218       "     See: https://github.com/scikit-learn/scikit-learn/issues/21755 */\n",219       "  display: inline-block !important;\n",220       "  position: relative;\n",221       "}\n",222       "\n",223       "#sk-container-id-1 div.sk-text-repr-fallback {\n",224       "  display: none;\n",225       "}\n",226       "\n",227       "div.sk-parallel-item,\n",228       "div.sk-serial,\n",229       "div.sk-item {\n",230       "  /* draw centered vertical line to link estimators */\n",231       "  background-image: linear-gradient(var(--sklearn-color-text-on-default-background), var(--sklearn-color-text-on-default-background));\n",232       "  background-size: 2px 100%;\n",233       "  background-repeat: no-repeat;\n",234       "  background-position: center center;\n",235       "}\n",236       "\n",237       "/* Parallel-specific style estimator block */\n",238       "\n",239       "#sk-container-id-1 div.sk-parallel-item::after {\n",240       "  content: \"\";\n",241       "  width: 100%;\n",242       "  border-bottom: 2px solid var(--sklearn-color-text-on-default-background);\n",243       "  flex-grow: 1;\n",244       "}\n",245       "\n",246       "#sk-container-id-1 div.sk-parallel {\n",247       "  display: flex;\n",248       "  align-items: stretch;\n",249       "  justify-content: center;\n",250       "  background-color: var(--sklearn-color-background);\n",251       "  position: relative;\n",252       "}\n",253       "\n",254       "#sk-container-id-1 div.sk-parallel-item {\n",255       "  display: flex;\n",256       "  flex-direction: column;\n",257       "}\n",258       "\n",259       "#sk-container-id-1 div.sk-parallel-item:first-child::after {\n",260       "  align-self: flex-end;\n",261       "  width: 50%;\n",262       "}\n",263       "\n",264       "#sk-container-id-1 div.sk-parallel-item:last-child::after {\n",265       "  align-self: flex-start;\n",266       "  width: 50%;\n",267       "}\n",268       "\n",269       "#sk-container-id-1 div.sk-parallel-item:only-child::after {\n",270       "  width: 0;\n",271       "}\n",272       "\n",273       "/* Serial-specific style estimator block */\n",274       "\n",275       "#sk-container-id-1 div.sk-serial {\n",276       "  display: flex;\n",277       "  flex-direction: column;\n",278       "  align-items: center;\n",279       "  background-color: var(--sklearn-color-background);\n",280       "  padding-right: 1em;\n",281       "  padding-left: 1em;\n",282       "}\n",283       "\n",284       "\n",285       "/* Toggleable style: style used for estimator/Pipeline/ColumnTransformer box that is\n",286       "clickable and can be expanded/collapsed.\n",287       "- Pipeline and ColumnTransformer use this feature and define the default style\n",288       "- Estimators will overwrite some part of the style using the `sk-estimator` class\n",289       "*/\n",290       "\n",291       "/* Pipeline and ColumnTransformer style (default) */\n",292       "\n",293       "#sk-container-id-1 div.sk-toggleable {\n",294       "  /* Default theme specific background. It is overwritten whether we have a\n",295       "  specific estimator or a Pipeline/ColumnTransformer */\n",296       "  background-color: var(--sklearn-color-background);\n",297       "}\n",298       "\n",299       "/* Toggleable label */\n",300       "#sk-container-id-1 label.sk-toggleable__label {\n",301       "  cursor: pointer;\n",302       "  display: flex;\n",303       "  width: 100%;\n",304       "  margin-bottom: 0;\n",305       "  padding: 0.5em;\n",306       "  box-sizing: border-box;\n",307       "  text-align: center;\n",308       "  align-items: start;\n",309       "  justify-content: space-between;\n",310       "  gap: 0.5em;\n",311       "}\n",312       "\n",313       "#sk-container-id-1 label.sk-toggleable__label .caption {\n",314       "  font-size: 0.6rem;\n",315       "  font-weight: lighter;\n",316       "  color: var(--sklearn-color-text-muted);\n",317       "}\n",318       "\n",319       "#sk-container-id-1 label.sk-toggleable__label-arrow:before {\n",320       "  /* Arrow on the left of the label */\n",321       "  content: \"โ–ธ\";\n",322       "  float: left;\n",323       "  margin-right: 0.25em;\n",324       "  color: var(--sklearn-color-icon);\n",325       "}\n",326       "\n",327       "#sk-container-id-1 label.sk-toggleable__label-arrow:hover:before {\n",328       "  color: var(--sklearn-color-text);\n",329       "}\n",330       "\n",331       "/* Toggleable content - dropdown */\n",332       "\n",333       "#sk-container-id-1 div.sk-toggleable__content {\n",334       "  max-height: 0;\n",335       "  max-width: 0;\n",336       "  overflow: hidden;\n",337       "  text-align: left;\n",338       "  /* unfitted */\n",339       "  background-color: var(--sklearn-color-unfitted-level-0);\n",340       "}\n",341       "\n",342       "#sk-container-id-1 div.sk-toggleable__content.fitted {\n",343       "  /* fitted */\n",344       "  background-color: var(--sklearn-color-fitted-level-0);\n",345       "}\n",346       "\n",347       "#sk-container-id-1 div.sk-toggleable__content pre {\n",348       "  margin: 0.2em;\n",349       "  border-radius: 0.25em;\n",350       "  color: var(--sklearn-color-text);\n",351       "  /* unfitted */\n",352       "  background-color: var(--sklearn-color-unfitted-level-0);\n",353       "}\n",354       "\n",355       "#sk-container-id-1 div.sk-toggleable__content.fitted pre {\n",356       "  /* unfitted */\n",357       "  background-color: var(--sklearn-color-fitted-level-0);\n",358       "}\n",359       "\n",360       "#sk-container-id-1 input.sk-toggleable__control:checked~div.sk-toggleable__content {\n",361       "  /* Expand drop-down */\n",362       "  max-height: 200px;\n",363       "  max-width: 100%;\n",364       "  overflow: auto;\n",365       "}\n",366       "\n",367       "#sk-container-id-1 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {\n",368       "  content: \"โ–พ\";\n",369       "}\n",370       "\n",371       "/* Pipeline/ColumnTransformer-specific style */\n",372       "\n",373       "#sk-container-id-1 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",374       "  color: var(--sklearn-color-text);\n",375       "  background-color: var(--sklearn-color-unfitted-level-2);\n",376       "}\n",377       "\n",378       "#sk-container-id-1 div.sk-label.fitted input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",379       "  background-color: var(--sklearn-color-fitted-level-2);\n",380       "}\n",381       "\n",382       "/* Estimator-specific style */\n",383       "\n",384       "/* Colorize estimator box */\n",385       "#sk-container-id-1 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",386       "  /* unfitted */\n",387       "  background-color: var(--sklearn-color-unfitted-level-2);\n",388       "}\n",389       "\n",390       "#sk-container-id-1 div.sk-estimator.fitted input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",391       "  /* fitted */\n",392       "  background-color: var(--sklearn-color-fitted-level-2);\n",393       "}\n",394       "\n",395       "#sk-container-id-1 div.sk-label label.sk-toggleable__label,\n",396       "#sk-container-id-1 div.sk-label label {\n",397       "  /* The background is the default theme color */\n",398       "  color: var(--sklearn-color-text-on-default-background);\n",399       "}\n",400       "\n",401       "/* On hover, darken the color of the background */\n",402       "#sk-container-id-1 div.sk-label:hover label.sk-toggleable__label {\n",403       "  color: var(--sklearn-color-text);\n",404       "  background-color: var(--sklearn-color-unfitted-level-2);\n",405       "}\n",406       "\n",407       "/* Label box, darken color on hover, fitted */\n",408       "#sk-container-id-1 div.sk-label.fitted:hover label.sk-toggleable__label.fitted {\n",409       "  color: var(--sklearn-color-text);\n",410       "  background-color: var(--sklearn-color-fitted-level-2);\n",411       "}\n",412       "\n",413       "/* Estimator label */\n",414       "\n",415       "#sk-container-id-1 div.sk-label label {\n",416       "  font-family: monospace;\n",417       "  font-weight: bold;\n",418       "  display: inline-block;\n",419       "  line-height: 1.2em;\n",420       "}\n",421       "\n",422       "#sk-container-id-1 div.sk-label-container {\n",423       "  text-align: center;\n",424       "}\n",425       "\n",426       "/* Estimator-specific */\n",427       "#sk-container-id-1 div.sk-estimator {\n",428       "  font-family: monospace;\n",429       "  border: 1px dotted var(--sklearn-color-border-box);\n",430       "  border-radius: 0.25em;\n",431       "  box-sizing: border-box;\n",432       "  margin-bottom: 0.5em;\n",433       "  /* unfitted */\n",434       "  background-color: var(--sklearn-color-unfitted-level-0);\n",435       "}\n",436       "\n",437       "#sk-container-id-1 div.sk-estimator.fitted {\n",438       "  /* fitted */\n",439       "  background-color: var(--sklearn-color-fitted-level-0);\n",440       "}\n",441       "\n",442       "/* on hover */\n",443       "#sk-container-id-1 div.sk-estimator:hover {\n",444       "  /* unfitted */\n",445       "  background-color: var(--sklearn-color-unfitted-level-2);\n",446       "}\n",447       "\n",448       "#sk-container-id-1 div.sk-estimator.fitted:hover {\n",449       "  /* fitted */\n",450       "  background-color: var(--sklearn-color-fitted-level-2);\n",451       "}\n",452       "\n",453       "/* Specification for estimator info (e.g. \"i\" and \"?\") */\n",454       "\n",455       "/* Common style for \"i\" and \"?\" */\n",456       "\n",457       ".sk-estimator-doc-link,\n",458       "a:link.sk-estimator-doc-link,\n",459       "a:visited.sk-estimator-doc-link {\n",460       "  float: right;\n",461       "  font-size: smaller;\n",462       "  line-height: 1em;\n",463       "  font-family: monospace;\n",464       "  background-color: var(--sklearn-color-background);\n",465       "  border-radius: 1em;\n",466       "  height: 1em;\n",467       "  width: 1em;\n",468       "  text-decoration: none !important;\n",469       "  margin-left: 0.5em;\n",470       "  text-align: center;\n",471       "  /* unfitted */\n",472       "  border: var(--sklearn-color-unfitted-level-1) 1pt solid;\n",473       "  color: var(--sklearn-color-unfitted-level-1);\n",474       "}\n",475       "\n",476       ".sk-estimator-doc-link.fitted,\n",477       "a:link.sk-estimator-doc-link.fitted,\n",478       "a:visited.sk-estimator-doc-link.fitted {\n",479       "  /* fitted */\n",480       "  border: var(--sklearn-color-fitted-level-1) 1pt solid;\n",481       "  color: var(--sklearn-color-fitted-level-1);\n",482       "}\n",483       "\n",484       "/* On hover */\n",485       "div.sk-estimator:hover .sk-estimator-doc-link:hover,\n",486       ".sk-estimator-doc-link:hover,\n",487       "div.sk-label-container:hover .sk-estimator-doc-link:hover,\n",488       ".sk-estimator-doc-link:hover {\n",489       "  /* unfitted */\n",490       "  background-color: var(--sklearn-color-unfitted-level-3);\n",491       "  color: var(--sklearn-color-background);\n",492       "  text-decoration: none;\n",493       "}\n",494       "\n",495       "div.sk-estimator.fitted:hover .sk-estimator-doc-link.fitted:hover,\n",496       ".sk-estimator-doc-link.fitted:hover,\n",497       "div.sk-label-container:hover .sk-estimator-doc-link.fitted:hover,\n",498       ".sk-estimator-doc-link.fitted:hover {\n",499       "  /* fitted */\n",500       "  background-color: var(--sklearn-color-fitted-level-3);\n",501       "  color: var(--sklearn-color-background);\n",502       "  text-decoration: none;\n",503       "}\n",504       "\n",505       "/* Span, style for the box shown on hovering the info icon */\n",506       ".sk-estimator-doc-link span {\n",507       "  display: none;\n",508       "  z-index: 9999;\n",509       "  position: relative;\n",510       "  font-weight: normal;\n",511       "  right: .2ex;\n",512       "  padding: .5ex;\n",513       "  margin: .5ex;\n",514       "  width: min-content;\n",515       "  min-width: 20ex;\n",516       "  max-width: 50ex;\n",517       "  color: var(--sklearn-color-text);\n",518       "  box-shadow: 2pt 2pt 4pt #999;\n",519       "  /* unfitted */\n",520       "  background: var(--sklearn-color-unfitted-level-0);\n",521       "  border: .5pt solid var(--sklearn-color-unfitted-level-3);\n",522       "}\n",523       "\n",524       ".sk-estimator-doc-link.fitted span {\n",525       "  /* fitted */\n",526       "  background: var(--sklearn-color-fitted-level-0);\n",527       "  border: var(--sklearn-color-fitted-level-3);\n",528       "}\n",529       "\n",530       ".sk-estimator-doc-link:hover span {\n",531       "  display: block;\n",532       "}\n",533       "\n",534       "/* \"?\"-specific style due to the `<a>` HTML tag */\n",535       "\n",536       "#sk-container-id-1 a.estimator_doc_link {\n",537       "  float: right;\n",538       "  font-size: 1rem;\n",539       "  line-height: 1em;\n",540       "  font-family: monospace;\n",541       "  background-color: var(--sklearn-color-background);\n",542       "  border-radius: 1rem;\n",543       "  height: 1rem;\n",544       "  width: 1rem;\n",545       "  text-decoration: none;\n",546       "  /* unfitted */\n",547       "  color: var(--sklearn-color-unfitted-level-1);\n",548       "  border: var(--sklearn-color-unfitted-level-1) 1pt solid;\n",549       "}\n",550       "\n",551       "#sk-container-id-1 a.estimator_doc_link.fitted {\n",552       "  /* fitted */\n",553       "  border: var(--sklearn-color-fitted-level-1) 1pt solid;\n",554       "  color: var(--sklearn-color-fitted-level-1);\n",555       "}\n",556       "\n",557       "/* On hover */\n",558       "#sk-container-id-1 a.estimator_doc_link:hover {\n",559       "  /* unfitted */\n",560       "  background-color: var(--sklearn-color-unfitted-level-3);\n",561       "  color: var(--sklearn-color-background);\n",562       "  text-decoration: none;\n",563       "}\n",564       "\n",565       "#sk-container-id-1 a.estimator_doc_link.fitted:hover {\n",566       "  /* fitted */\n",567       "  background-color: var(--sklearn-color-fitted-level-3);\n",568       "}\n",569       "</style><div id=\"sk-container-id-1\" class=\"sk-top-container\"><div class=\"sk-text-repr-fallback\"><pre>RandomForestClassifier(random_state=42)</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>RandomForestClassifier</div></div><div><a class=\"sk-estimator-doc-link fitted\" rel=\"noreferrer\" target=\"_blank\" href=\"https://scikit-learn.org/1.6/modules/generated/sklearn.ensemble.RandomForestClassifier.html\">?<span>Documentation for RandomForestClassifier</span></a><span class=\"sk-estimator-doc-link fitted\">i<span>Fitted</span></span></div></label><div class=\"sk-toggleable__content fitted\"><pre>RandomForestClassifier(random_state=42)</pre></div> </div></div></div></div>"570      ],571      "text/plain": [572       "RandomForestClassifier(random_state=42)"573      ]574     },575     "execution_count": 6,576     "metadata": {},577     "output_type": "execute_result"578    }579   ],580   "source": [581    "model = RandomForestClassifier(n_estimators=100, random_state=42)\n",582    "model.fit(X_train, y_train)"583   ]584  },585  {586   "cell_type": "code",587   "execution_count": 7,588   "id": "79735cfe",589   "metadata": {},590   "outputs": [591    {592     "name": "stdout",593     "output_type": "stream",594     "text": [595      "Classification Report:\n",596      "               precision    recall  f1-score   support\n",597      "\n",598      "      Change       0.97      0.55      0.70       762\n",599      "    Incident       0.65      0.98      0.78      2869\n",600      "     Problem       0.80      0.10      0.18      1484\n",601      "     Request       0.85      0.92      0.88      2085\n",602      "\n",603      "    accuracy                           0.73      7200\n",604      "   macro avg       0.82      0.64      0.64      7200\n",605      "weighted avg       0.77      0.73      0.68      7200\n",606      "\n",607      "Model and Vectorizer have been save\n"608     ]609    }610   ],611   "source": [612    "# Step 6: Evaluate the model performance on the test set\n",613    "y_pred = model.predict(X_test)\n",614    "print(\"Classification Report:\\n\", classification_report(y_test, y_pred))\n",615    "\n",616    "# Step 7: Save the trained model and vectorizer using pickle\n",617    "with open('email_classifier_model.pkl', 'wb') as model_file:\n",618    "    pickle.dump(model, model_file)\n",619    "\n",620    "with open('vectorizer.pkl', 'wb') as vec_file:\n",621    "    pickle.dump(vectorizer, vec_file)\n",622    "\n",623    "print(\"Model and Vectorizer have been save\")"624   ]625  },626  {627   "cell_type": "code",628   "execution_count": null,629   "id": "58b822fc",630   "metadata": {},631   "outputs": [],632   "source": []633  },634  {635   "cell_type": "code",636   "execution_count": null,637   "id": "b15eaad2",638   "metadata": {},639   "outputs": [],640   "source": []641  }642 ],643 "metadata": {644  "kernelspec": {645   "display_name": "Python 3",646   "language": "python",647   "name": "python3"648  },649  "language_info": {650   "codemirror_mode": {651    "name": "ipython",652    "version": 3653   },654   "file_extension": ".py",655   "mimetype": "text/x-python",656   "name": "python",657   "nbconvert_exporter": "python",658   "pygments_lexer": "ipython3",659   "version": "3.12.0"660  }661 },662 "nbformat": 4,663 "nbformat_minor": 5664}665