{"id":28430642,"url":"https://github.com/sagarprajapat2004/spam_ham_classification","last_synced_at":"2025-07-20T01:06:34.338Z","repository":{"id":295934330,"uuid":"991736839","full_name":"sagarprajapat2004/Spam_Ham_Classification","owner":"sagarprajapat2004","description":"A Data Science\u0026Machine Learning\u0026NLP-powered Flask Web Application that classifies Email/SMS messages as either Spam or Ham (Not Spam).","archived":false,"fork":false,"pushed_at":"2025-06-02T10:11:31.000Z","size":2671,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-07-04T21:39:07.432Z","etag":null,"topics":["data-science","flask","knearest-neighbors-classifier","machine-learning","multinomial-naive-bayes","python","random-forest-classifier","svm-classifier"],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sagarprajapat2004.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-05-28T04:42:37.000Z","updated_at":"2025-06-02T10:11:34.000Z","dependencies_parsed_at":"2025-05-28T05:36:28.753Z","dependency_job_id":"e252c992-a551-4b67-ad98-5be2f426a2ff","html_url":"https://github.com/sagarprajapat2004/Spam_Ham_Classification","commit_stats":null,"previous_names":["sagarprajapat2004/spam_ham_classification"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/sagarprajapat2004/Spam_Ham_Classification","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sagarprajapat2004%2FSpam_Ham_Classification","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sagarprajapat2004%2FSpam_Ham_Classification/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sagarprajapat2004%2FSpam_Ham_Classification/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sagarprajapat2004%2FSpam_Ham_Classification/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sagarprajapat2004","download_url":"https://codeload.github.com/sagarprajapat2004/Spam_Ham_Classification/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sagarprajapat2004%2FSpam_Ham_Classification/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266052535,"owners_count":23869475,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["data-science","flask","knearest-neighbors-classifier","machine-learning","multinomial-naive-bayes","python","random-forest-classifier","svm-classifier"],"created_at":"2025-06-05T14:07:39.132Z","updated_at":"2025-07-20T01:06:34.320Z","avatar_url":"https://github.com/sagarprajapat2004.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Email/SMS Spam-Ham Classification\n\u003cimg width=\"1392\" alt=\"Screenshot 2025-06-02 at 3 24 28 PM\" src=\"https://github.com/user-attachments/assets/0347955e-8270-4838-896c-b9e6006ad1b1\" /\u003e\n\n\n\nA Data Science \u0026 Machine Learning-powered Flask Web Application that classifies Email/SMS messages as either **Spam** or **Ham** (Not Spam).\n\n---\n\n## 📌 Project Overview\n\nThis project demonstrates how **Natural Language Processing (NLP)** and **Machine Learning** can be used to classify text messages. It includes data cleaning, EDA, feature engineering, model building, and deployment in a real-time Web Application.\n\n---\n\n## 🧩 Problem Statement\n\nWith the ever-growing volume of digital communication, especially SMS and Email, distinguishing between legitimate messages and unwanted spam is critical. Spam messages often carry scams, phishing links, or irrelevant promotions that compromise user experience and safety.\n\n---\n\n## 💡 Why This Project Is Useful\n\nThis project provides an end-to-end solution for spam detection, from data preprocessing and feature engineering to deploying a real-time Flask Web Application. It helps automate message classification, enhancing communication security and saving users from spam clutter.\n\n---\n\n## 📦 Dataset \u0026 Preparation\n\n- **Source**: [Kaggle SMS Spam Collection Dataset](https://www.kaggle.com/datasets/satyajeetbedi/email-hamspam-dataset)\n- **Initial Shape**: 5572 rows × 5 columns\n- **Preprocessing**:\n  - Dropped irrelevant columns: `Unnamed: 2`, `Unnamed: 3`, `Unnamed: 4`\n  - Renamed: `v1` → `label`, `v2` → `message`\n  - Removed 403 duplicate rows\n\n---\n\n## 📊 Exploratory Data Analysis (EDA)\n\n- **Class Distribution**:\n  - **Ham**: 87.4%\n  - **Spam**: 12.6%\n- **Feature Creation**:\n  - `num_of_char`: Total characters\n  - `num_of_words`: Total words (`nltk.tokenize.word_tokenize`)\n  - `num_of_sentences`: Sentence count\n- **Visualizations**:\n  - Pie chart of class distribution\n  - Bar charts \u0026 histograms for custom features\n  - Pairplot for feature relationships\n  - Word frequency bar plots for both spam and ham\n- Dropped temporary features after insights\n\n---\n\n## 🧹 Text Preprocessing\n\nImplemented a custom text transformation pipeline:\n\n- Lowercasing\n- Tokenization with `nltk`\n- Stopword removal (including HTML tags, emojis, punctuation, digits)\n- Lemmatization \u0026 Stemming using `PorterStemmer`\n- Dropped 87 duplicates after text transformation\n\n---\n\n## ⚙️ Feature Engineering\n\n- Generated word clouds for:\n  - **Spam** (e.g., \"free\", \"win\", \"txt\", \"offer\")\n  - **Ham** (e.g., \"love\", \"ok\", \"come\", \"home\")\n- Vectorized text using `CountVectorizer`\n- Applied `StratifiedShuffleSplit` to ensure balanced train/test splits\n\n---\n\n## 🤖 Model Building \u0026 Evaluation\n\nTested the following classifiers:\n\n- `MultinomialNB`\n- `RandomForestClassifier`\n- `SVC`\n- `KNeighborsClassifier`\n\n**Evaluation Metrics**: Accuracy, Precision, Confusion Matrix\n\n### 📋 Results Summary:\n\n```\n| Algorithm | Training_Accuracy | Test_Accuracy | Training_Precision | Test_Precision |\n|-----------|-------------------|---------------|---------------------|----------------|\n| MNB       | 0.9909            | 0.9715        | 0.9676              | 0.8750         |\n| RF        | 1.0000            | 0.9626        | 1.0000              | 1.0000         |\n| SVC       | 0.9956            | 0.9607        | 1.0000              | 0.9885         |\n| KNN       | 0.9262            | 0.9105        | 1.0000              | 1.0000         |\n```\n\n✅ **Best Model**: `RandomForestClassifier`\n\n---\n\n## 🚀 Deployment\n\n- Saved final model and vectorizer using `pickle`\n- Deployed using **Flask** for real-time predictions\n- Users can input a message and receive immediate spam/ham classification\n\n---\n\n## 🛠️ Technologies Used\n\n- **Programming**: Python\n- **Libraries**: Pandas, Numpy, NLTK, Scikit-learn\n- **Visualization**: Matplotlib, Seaborn, WordCloud\n- **Web Framework**: Flask\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsagarprajapat2004%2Fspam_ham_classification","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsagarprajapat2004%2Fspam_ham_classification","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsagarprajapat2004%2Fspam_ham_classification/lists"}