From fb2dd046c89be2fec00a7e95099002be53a13419 Mon Sep 17 00:00:00 2001
From: Sayantika Laskar <127471376+SayantikaLaskar@users.noreply.github.com>
Date: Sat, 8 Jun 2024 10:40:07 +0530
Subject: [PATCH] Add spam mail detection
---
Spam Mail Classifier/README.md | 96 ++
...rediction_using_Machine_Learning (1).ipynb | 927 ++++++++++++++++++
2 files changed, 1023 insertions(+)
create mode 100644 Spam Mail Classifier/README.md
create mode 100644 Spam Mail Classifier/Spam_Mail_Prediction_using_Machine_Learning (1).ipynb
diff --git a/Spam Mail Classifier/README.md b/Spam Mail Classifier/README.md
new file mode 100644
index 000000000..f0302c3ae
--- /dev/null
+++ b/Spam Mail Classifier/README.md
@@ -0,0 +1,96 @@
+# Spam Mail Detection Project
+
+## Overview
+
+Welcome to the Spam Mail Detection Project! This project aims to develop a machine learning model to classify emails as spam or not spam. The primary objective is to provide an efficient and accurate tool to filter out unwanted spam emails from the user's inbox. This project is a part of the Girl Script Summer of Code (GSSOC) 2024 initiative.
+
+## Table of Contents
+
+1. [Introduction](#introduction)
+2. [Features](#features)
+3. [Installation](#installation)
+4. [Usage](#usage)
+5. [Model Training](#model-training)
+6. [License](#license)
+
+## Introduction
+
+Spam emails are a significant issue for many users, leading to wasted time and potential security threats. Our project leverages machine learning techniques to identify and filter out spam emails. The model will be trained on a labeled dataset of emails and will use various features extracted from the email content and metadata.
+
+## Features
+
+- **Email Preprocessing**: Clean and preprocess email data for model training.
+- **Feature Extraction**: Extract relevant features from emails, such as word frequency, email headers, and metadata.
+- **Model Training**: Train a machine learning model using the preprocessed and feature-extracted data.
+- **Spam Detection**: Classify new emails as spam or not spam using the trained model.
+- **Evaluation Metrics**: Evaluate the performance of the model using accuracy, precision, recall, and F1-score.
+
+## Installation
+
+To set up the project locally, follow these steps:
+
+1. Clone the repository:
+ ```sh
+ git clone https://github.com/yourusername/spam-mail-detection.git
+ cd spam-mail-detection
+ ```
+
+2. Create a virtual environment and activate it:
+ ```sh
+ python -m venv venv
+ source venv/bin/activate # On Windows, use `venv\Scripts\activate`
+ ```
+
+3. Install the required dependencies:
+ ```sh
+ pip install -r requirements.txt
+ ```
+
+## Usage
+
+1. **Data Preprocessing**:
+ - Run the preprocessing script to clean and prepare the email data:
+ ```sh
+ python preprocess.py
+ ```
+
+2. **Feature Extraction**:
+ - Extract features from the preprocessed data:
+ ```sh
+ python feature_extraction.py
+ ```
+
+3. **Model Training**:
+ - Train the machine learning model:
+ ```sh
+ python train_model.py
+ ```
+
+4. **Spam Detection**:
+ - Use the trained model to classify new emails:
+ ```sh
+ python predict.py --email "path_to_email_file"
+ ```
+
+
+## Model Training
+
+The model training process involves the following steps:
+
+1. Load and preprocess the dataset.
+2. Extract features from the emails.
+3. Split the data into training and testing sets.
+4. Train a machine learning model (e.g., Naive Bayes, SVM, Random Forest).
+5. Evaluate the model using appropriate metrics.
+
+
+## License
+
+This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for more details.
+
+
+We hope you find this project useful and look forward to your contributions!
+
+---
+
+*This project is developed as part of the Girl Script Summer of Code (GSSOC) 2024 initiative.*
\ No newline at end of file
diff --git a/Spam Mail Classifier/Spam_Mail_Prediction_using_Machine_Learning (1).ipynb b/Spam Mail Classifier/Spam_Mail_Prediction_using_Machine_Learning (1).ipynb
new file mode 100644
index 000000000..612d95889
--- /dev/null
+++ b/Spam Mail Classifier/Spam_Mail_Prediction_using_Machine_Learning (1).ipynb
@@ -0,0 +1,927 @@
+{
+ "nbformat": 4,
+ "nbformat_minor": 0,
+ "metadata": {
+ "colab": {
+ "provenance": []
+ },
+ "kernelspec": {
+ "name": "python3",
+ "display_name": "Python 3"
+ },
+ "language_info": {
+ "name": "python"
+ }
+ },
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "source": [
+ "Imorting the Dependencies"
+ ],
+ "metadata": {
+ "id": "fjWeEGD-0EtH"
+ }
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "id": "n8w458Fyyeft"
+ },
+ "outputs": [],
+ "source": [
+ "import numpy as np\n",
+ "import pandas as pd\n",
+ "from sklearn.model_selection import train_test_split\n",
+ "from sklearn.feature_extraction.text import TfidfVectorizer\n",
+ "from sklearn.linear_model import LogisticRegression\n",
+ "from sklearn.metrics import accuracy_score"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "source": [
+ "Data Collection & Pre-processing"
+ ],
+ "metadata": {
+ "id": "nXr7GETI1uv-"
+ }
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "# loading the data from csv file to a pandas dataframe\n",
+ "raw_mail_data = pd.read_csv('/content/mail_data.csv')"
+ ],
+ "metadata": {
+ "id": "TEy05ApM1g41"
+ },
+ "execution_count": null,
+ "outputs": []
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "print(raw_mail_data)"
+ ],
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ },
+ "id": "xePFRWCm2FRc",
+ "outputId": "6f87fc00-1328-476c-8033-bcd14c3a06d8"
+ },
+ "execution_count": null,
+ "outputs": [
+ {
+ "output_type": "stream",
+ "name": "stdout",
+ "text": [
+ " Category Message\n",
+ "0 ham Go until jurong point, crazy.. Available only ...\n",
+ "1 ham Ok lar... Joking wif u oni...\n",
+ "2 spam Free entry in 2 a wkly comp to win FA Cup fina...\n",
+ "3 ham U dun say so early hor... U c already then say...\n",
+ "4 ham Nah I don't think he goes to usf, he lives aro...\n",
+ "... ... ...\n",
+ "5567 spam This is the 2nd time we have tried 2 contact u...\n",
+ "5568 ham Will ü b going to esplanade fr home?\n",
+ "5569 ham Pity, * was in mood for that. So...any other s...\n",
+ "5570 ham The guy did some bitching but I acted like i'd...\n",
+ "5571 ham Rofl. Its true to its name\n",
+ "\n",
+ "[5572 rows x 2 columns]\n"
+ ]
+ }
+ ]
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "# replace null values with a null string\n",
+ "mail_data = raw_mail_data.where((pd.notnull(raw_mail_data)), '')"
+ ],
+ "metadata": {
+ "id": "y2rsT5nT2JBA"
+ },
+ "execution_count": null,
+ "outputs": []
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "# printing the first 5 rows of the dataframe\n",
+ "mail_data.head()"
+ ],
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 206
+ },
+ "id": "fWXv7COg272M",
+ "outputId": "b44f1e80-e0f7-4a6f-f1f5-a23316323f08"
+ },
+ "execution_count": null,
+ "outputs": [
+ {
+ "output_type": "execute_result",
+ "data": {
+ "text/plain": [
+ " Category Message\n",
+ "0 ham Go until jurong point, crazy.. Available only ...\n",
+ "1 ham Ok lar... Joking wif u oni...\n",
+ "2 spam Free entry in 2 a wkly comp to win FA Cup fina...\n",
+ "3 ham U dun say so early hor... U c already then say...\n",
+ "4 ham Nah I don't think he goes to usf, he lives aro..."
+ ],
+ "text/html": [
+ "\n",
+ "
\n",
+ "
\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " Category | \n",
+ " Message | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " 0 | \n",
+ " ham | \n",
+ " Go until jurong point, crazy.. Available only ... | \n",
+ "
\n",
+ " \n",
+ " 1 | \n",
+ " ham | \n",
+ " Ok lar... Joking wif u oni... | \n",
+ "
\n",
+ " \n",
+ " 2 | \n",
+ " spam | \n",
+ " Free entry in 2 a wkly comp to win FA Cup fina... | \n",
+ "
\n",
+ " \n",
+ " 3 | \n",
+ " ham | \n",
+ " U dun say so early hor... U c already then say... | \n",
+ "
\n",
+ " \n",
+ " 4 | \n",
+ " ham | \n",
+ " Nah I don't think he goes to usf, he lives aro... | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
\n",
+ "
\n",
+ "
\n"
+ ]
+ },
+ "metadata": {},
+ "execution_count": 6
+ }
+ ]
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "# checking the number of rows and columns in the dataframe\n",
+ "mail_data.shape"
+ ],
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ },
+ "id": "a9q3ycSH3Dyd",
+ "outputId": "b4c74161-8e31-4542-fc21-ef3d6ac51e8d"
+ },
+ "execution_count": null,
+ "outputs": [
+ {
+ "output_type": "execute_result",
+ "data": {
+ "text/plain": [
+ "(5572, 2)"
+ ]
+ },
+ "metadata": {},
+ "execution_count": 7
+ }
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "source": [
+ "Label Encoding"
+ ],
+ "metadata": {
+ "id": "xhR7s_t13pkA"
+ }
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "# label spam mail as 0; ham mail as 1\n",
+ "\n",
+ "mail_data.loc[mail_data['Category'] == 'spam', 'Category',] = 0\n",
+ "mail_data.loc[mail_data['Category'] == 'ham', 'Category',] = 1"
+ ],
+ "metadata": {
+ "id": "kansbBdx3TAz"
+ },
+ "execution_count": null,
+ "outputs": []
+ },
+ {
+ "cell_type": "markdown",
+ "source": [
+ "spam - 0\n",
+ "ham - 1"
+ ],
+ "metadata": {
+ "id": "2gD99sNg4YM5"
+ }
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "# separating the data as text and label\n",
+ "\n",
+ "X = mail_data['Message']\n",
+ "\n",
+ "Y = mail_data['Category']"
+ ],
+ "metadata": {
+ "id": "Z9K7sXtz4Vsh"
+ },
+ "execution_count": null,
+ "outputs": []
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "print(X)"
+ ],
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ },
+ "id": "oJZ4hpg746Bu",
+ "outputId": "aac864bd-dfb4-441f-f21c-72ae47b6c621"
+ },
+ "execution_count": null,
+ "outputs": [
+ {
+ "output_type": "stream",
+ "name": "stdout",
+ "text": [
+ "0 Go until jurong point, crazy.. Available only ...\n",
+ "1 Ok lar... Joking wif u oni...\n",
+ "2 Free entry in 2 a wkly comp to win FA Cup fina...\n",
+ "3 U dun say so early hor... U c already then say...\n",
+ "4 Nah I don't think he goes to usf, he lives aro...\n",
+ " ... \n",
+ "5567 This is the 2nd time we have tried 2 contact u...\n",
+ "5568 Will ü b going to esplanade fr home?\n",
+ "5569 Pity, * was in mood for that. So...any other s...\n",
+ "5570 The guy did some bitching but I acted like i'd...\n",
+ "5571 Rofl. Its true to its name\n",
+ "Name: Message, Length: 5572, dtype: object\n"
+ ]
+ }
+ ]
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "print(Y)"
+ ],
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ },
+ "id": "OCnwQusp47zP",
+ "outputId": "75cc459e-e541-48b5-93c2-ded8789a0838"
+ },
+ "execution_count": null,
+ "outputs": [
+ {
+ "output_type": "stream",
+ "name": "stdout",
+ "text": [
+ "0 1\n",
+ "1 1\n",
+ "2 0\n",
+ "3 1\n",
+ "4 1\n",
+ " ..\n",
+ "5567 0\n",
+ "5568 1\n",
+ "5569 1\n",
+ "5570 1\n",
+ "5571 1\n",
+ "Name: Category, Length: 5572, dtype: object\n"
+ ]
+ }
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "source": [
+ "Splitting the data into training data and test data"
+ ],
+ "metadata": {
+ "id": "bXsx8Aaf5EHC"
+ }
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=0.2, random_state=3)"
+ ],
+ "metadata": {
+ "id": "aSjY5OTx49tP"
+ },
+ "execution_count": null,
+ "outputs": []
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "print(X.shape)\n",
+ "print(X_train.shape)\n",
+ "print(X_test.shape)"
+ ],
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ },
+ "id": "tMquKtlh6Lxu",
+ "outputId": "e0178f5a-21ac-4194-c595-1a81654752de"
+ },
+ "execution_count": null,
+ "outputs": [
+ {
+ "output_type": "stream",
+ "name": "stdout",
+ "text": [
+ "(5572,)\n",
+ "(4457,)\n",
+ "(1115,)\n"
+ ]
+ }
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "source": [
+ "Feature Extraction"
+ ],
+ "metadata": {
+ "id": "kCX1EKnJ6l4x"
+ }
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "from sklearn.feature_extraction.text import TfidfVectorizer\n",
+ "\n",
+ "# transform the test data to feature vectors that can be used as input to the Logistic regression\n",
+ "\n",
+ "feature_extraction = TfidfVectorizer(min_df=1, stop_words='english', lowercase=True)\n",
+ "\n",
+ "X_train_features = feature_extraction.fit_transform(X_train)\n",
+ "X_test_features = feature_extraction.transform(X_test)\n",
+ "\n",
+ "# Convert Y_train and Y_test values to integers\n",
+ "Y_train = Y_train.astype('int')\n",
+ "Y_test = Y_test.astype('int')\n"
+ ],
+ "metadata": {
+ "id": "JyAmeXa26Xye"
+ },
+ "execution_count": null,
+ "outputs": []
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "print(X_train)"
+ ],
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ },
+ "id": "zy9BjMhg9siT",
+ "outputId": "08ab590c-049b-496d-97a1-4b78048807f3"
+ },
+ "execution_count": null,
+ "outputs": [
+ {
+ "output_type": "stream",
+ "name": "stdout",
+ "text": [
+ "3075 Don know. I did't msg him recently.\n",
+ "1787 Do you know why god created gap between your f...\n",
+ "1614 Thnx dude. u guys out 2nite?\n",
+ "4304 Yup i'm free...\n",
+ "3266 44 7732584351, Do you want a New Nokia 3510i c...\n",
+ " ... \n",
+ "789 5 Free Top Polyphonic Tones call 087018728737,...\n",
+ "968 What do u want when i come back?.a beautiful n...\n",
+ "1667 Guess who spent all last night phasing in and ...\n",
+ "3321 Eh sorry leh... I din c ur msg. Not sad alread...\n",
+ "1688 Free Top ringtone -sub to weekly ringtone-get ...\n",
+ "Name: Message, Length: 4457, dtype: object\n"
+ ]
+ }
+ ]
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "print(X_train_features)"
+ ],
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ },
+ "id": "kWNtiRsSACQq",
+ "outputId": "f4fcb312-2e62-477d-a18a-da79bb2c36ac"
+ },
+ "execution_count": null,
+ "outputs": [
+ {
+ "output_type": "stream",
+ "name": "stdout",
+ "text": [
+ " (0, 5413)\t0.6198254967574347\n",
+ " (0, 4456)\t0.4168658090846482\n",
+ " (0, 2224)\t0.413103377943378\n",
+ " (0, 3811)\t0.34780165336891333\n",
+ " (0, 2329)\t0.38783870336935383\n",
+ " (1, 4080)\t0.18880584110891163\n",
+ " (1, 3185)\t0.29694482957694585\n",
+ " (1, 3325)\t0.31610586766078863\n",
+ " (1, 2957)\t0.3398297002864083\n",
+ " (1, 2746)\t0.3398297002864083\n",
+ " (1, 918)\t0.22871581159877646\n",
+ " (1, 1839)\t0.2784903590561455\n",
+ " (1, 2758)\t0.3226407885943799\n",
+ " (1, 2956)\t0.33036995955537024\n",
+ " (1, 1991)\t0.33036995955537024\n",
+ " (1, 3046)\t0.2503712792613518\n",
+ " (1, 3811)\t0.17419952275504033\n",
+ " (2, 407)\t0.509272536051008\n",
+ " (2, 3156)\t0.4107239318312698\n",
+ " (2, 2404)\t0.45287711070606745\n",
+ " (2, 6601)\t0.6056811524587518\n",
+ " (3, 2870)\t0.5864269879324768\n",
+ " (3, 7414)\t0.8100020912469564\n",
+ " (4, 50)\t0.23633754072626942\n",
+ " (4, 5497)\t0.15743785051118356\n",
+ " :\t:\n",
+ " (4454, 4602)\t0.2669765732445391\n",
+ " (4454, 3142)\t0.32014451677763156\n",
+ " (4455, 2247)\t0.37052851863170466\n",
+ " (4455, 2469)\t0.35441545511837946\n",
+ " (4455, 5646)\t0.33545678464631296\n",
+ " (4455, 6810)\t0.29731757715898277\n",
+ " (4455, 6091)\t0.23103841516927642\n",
+ " (4455, 7113)\t0.30536590342067704\n",
+ " (4455, 3872)\t0.3108911491788658\n",
+ " (4455, 4715)\t0.30714144758811196\n",
+ " (4455, 6916)\t0.19636985317119715\n",
+ " (4455, 3922)\t0.31287563163368587\n",
+ " (4455, 4456)\t0.24920025316220423\n",
+ " (4456, 141)\t0.292943737785358\n",
+ " (4456, 647)\t0.30133182431707617\n",
+ " (4456, 6311)\t0.30133182431707617\n",
+ " (4456, 5569)\t0.4619395404299172\n",
+ " (4456, 6028)\t0.21034888000987115\n",
+ " (4456, 7154)\t0.24083218452280053\n",
+ " (4456, 7150)\t0.3677554681447669\n",
+ " (4456, 6249)\t0.17573831794959716\n",
+ " (4456, 6307)\t0.2752760476857975\n",
+ " (4456, 334)\t0.2220077711654938\n",
+ " (4456, 5778)\t0.16243064490100795\n",
+ " (4456, 2870)\t0.31523196273113385\n"
+ ]
+ }
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "source": [
+ "Training the Model"
+ ],
+ "metadata": {
+ "id": "Pva5RHYdAXZ6"
+ }
+ },
+ {
+ "cell_type": "markdown",
+ "source": [
+ "Logistic Regression"
+ ],
+ "metadata": {
+ "id": "GecnPeGQAaQY"
+ }
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "model = LogisticRegression()"
+ ],
+ "metadata": {
+ "id": "L0vJOJWEAHh7"
+ },
+ "execution_count": null,
+ "outputs": []
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "# training the Logistic Regression model with the training data\n",
+ "model.fit(X_train_features, Y_train)"
+ ],
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 75
+ },
+ "id": "arWwqBNsAlr4",
+ "outputId": "8ed56123-c774-4ef4-beaf-5b88376d8406"
+ },
+ "execution_count": null,
+ "outputs": [
+ {
+ "output_type": "execute_result",
+ "data": {
+ "text/plain": [
+ "LogisticRegression()"
+ ],
+ "text/html": [
+ "LogisticRegression()
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org. "
+ ]
+ },
+ "metadata": {},
+ "execution_count": 23
+ }
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "source": [
+ "Evaluating the trained model"
+ ],
+ "metadata": {
+ "id": "r8cYckM1A7XZ"
+ }
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "# prediction on training data\n",
+ "\n",
+ "prediction_on_training_data = model.predict(X_train_features)\n",
+ "accuracy_on_training_data = accuracy_score(Y_train, prediction_on_training_data)"
+ ],
+ "metadata": {
+ "id": "tQAxlE6SA1FZ"
+ },
+ "execution_count": null,
+ "outputs": []
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "print('Accuracy on training data : ', accuracy_on_training_data)"
+ ],
+ "metadata": {
+ "id": "jZ6YrljxBfVJ",
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ },
+ "outputId": "0c816d93-1eb1-40fc-d67d-9276cc78cd62"
+ },
+ "execution_count": null,
+ "outputs": [
+ {
+ "output_type": "stream",
+ "name": "stdout",
+ "text": [
+ "Accuracy on training data : 0.9670181736594121\n"
+ ]
+ }
+ ]
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "# prediction on training data\n",
+ "\n",
+ "prediction_on_test_data = model.predict(X_test_features)\n",
+ "accuracy_on_test_data = accuracy_score(Y_test, prediction_on_test_data)"
+ ],
+ "metadata": {
+ "id": "R00nGZjsDG8E"
+ },
+ "execution_count": null,
+ "outputs": []
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "print('Accuracy on test data : ', accuracy_on_test_data)"
+ ],
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ },
+ "id": "1RskbscVDfKK",
+ "outputId": "7ffcd95c-3a64-4608-a114-6d57b4cc7e73"
+ },
+ "execution_count": null,
+ "outputs": [
+ {
+ "output_type": "stream",
+ "name": "stdout",
+ "text": [
+ "Accuracy on test data : 0.9659192825112107\n"
+ ]
+ }
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "source": [
+ "Building a Predictive System"
+ ],
+ "metadata": {
+ "id": "ReFsV1WjELoS"
+ }
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "input_mail = [\"I've been searching for the right words to thank you for this breather. I promise i wont take your help for granted and will fulfil my promise. You have been wonderful and a blessing at all times.\"]\n",
+ "\n",
+ "# convert text to feature vectors\n",
+ "input_data_features = feature_extraction.transform(input_mail)\n",
+ "\n",
+ "# making predictions\n",
+ "\n",
+ "prediction = model.predict(input_data_features)\n",
+ "print(prediction)\n",
+ "\n",
+ "\n",
+ "if (prediction[0]==1):\n",
+ " print('Ham mail')\n",
+ "\n",
+ "else:\n",
+ " print('Spam mail')"
+ ],
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ },
+ "id": "Btg42OqdDkCH",
+ "outputId": "74932794-0527-451d-b257-fc281e5f2648"
+ },
+ "execution_count": null,
+ "outputs": [
+ {
+ "output_type": "stream",
+ "name": "stdout",
+ "text": [
+ "[1]\n",
+ "Ham mail\n"
+ ]
+ }
+ ]
+ }
+ ]
+}
\ No newline at end of file