{"id":43272405,"url":"https://github.com/lorenanicole/python-naive-bayes-spam-classifier","last_synced_at":"2026-02-01T16:05:03.028Z","repository":{"id":34161313,"uuid":"38004822","full_name":"lorenanicole/python-naive-bayes-spam-classifier","owner":"lorenanicole","description":"Python 2 and Python 3 naive bayes spam classifier trained with nltk.","archived":false,"fork":false,"pushed_at":"2018-11-20T22:17:08.000Z","size":16227,"stargazers_count":5,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-04-14T23:02:05.049Z","etag":null,"topics":["jupyter-notebook","naive-bayes-classifier","nltk-python","notebook","python","spam","virtualenv"],"latest_commit_sha":null,"homepage":"","language":"Python","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/lorenanicole.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}},"created_at":"2015-06-24T18:56:00.000Z","updated_at":"2022-02-27T07:55:32.000Z","dependencies_parsed_at":"2022-09-02T13:30:44.714Z","dependency_job_id":null,"html_url":"https://github.com/lorenanicole/python-naive-bayes-spam-classifier","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/lorenanicole/python-naive-bayes-spam-classifier","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lorenanicole%2Fpython-naive-bayes-spam-classifier","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lorenanicole%2Fpython-naive-bayes-spam-classifier/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lorenanicole%2Fpython-naive-bayes-spam-classifier/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lorenanicole%2Fpython-naive-bayes-spam-classifier/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lorenanicole","download_url":"https://codeload.github.com/lorenanicole/python-naive-bayes-spam-classifier/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lorenanicole%2Fpython-naive-bayes-spam-classifier/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28981893,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-01T15:35:50.179Z","status":"ssl_error","status_checked_at":"2026-02-01T15:35:38.075Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["jupyter-notebook","naive-bayes-classifier","nltk-python","notebook","python","spam","virtualenv"],"created_at":"2026-02-01T16:05:01.977Z","updated_at":"2026-02-01T16:05:03.024Z","avatar_url":"https://github.com/lorenanicole.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"### Basic Naive Bayes Classifier in Python\n\nThis approach makes use of pre-labeled data provided by the [Kaggle Classroom spam detection challenge](https://inclass.kaggle.com/c/adcg-ss14-challenge-02-spam-mails-detection/data).\n\n### `naive-bayes` Python 2 Classifier\n\nPython project code in `naive-bayes` is written with Python 2.7.\n\nFor setup create a virtualenv with the requirements:\n\n```\nvirtualenv nbenv\nsource nbenv/bin/activate\npip install -r pathway/to/naive-baves/requirements.txt\n```\n\nTo run the Naive Bayes classifier: \n\n```\ncd naive-bayes\npython spam_detector.py\n```\n### Python 3 Jupyter Notebook\n\nThe Python 2.7 project has been ported to Python 3 and can be run in the Jupyter notebook.\n\nFirst you will want to create a Python3 virtualenv:\n\n```\npyenv-3.5 python3env  # Update 3.5 with your version of Python 3\nsource python3env/bin/activate  # Name your env whatever you like!\npip3 install -r requirements.txt \n``` \nThen start the notebook!\n\n```\njupyter notebook\n```\n\n### Notes on Python Naive Bayes Implementation\n\nYou can have the detector either train and evaluate itself against the training data (using 90% of the pre-labeled data as training and 10% to label) with: \n\n```\ndetector.train_and_evaluate()\n```\n\nOr you can train against the entire labeled data set (2500 emails) and classify on the unlabeled data (1827 emails).\n\n```\ndetector.train()\ndetector.classify(1827)  # Number of emails to classify\n```\n\nHam has a label of 1 while Spam has a label of 0.\n\n### How Naive Bayes Implemented\n\nThis solution makes use of [Python's 2.7 Decimal module](https://docs.python.org/2/library/decimal.html), which is used for floating point arithmetic. (Prevents [floating point underflow](http://nlp.stanford.edu/IR-book/html/htmledition/naive-bayes-text-classification-1.html)!)\n\nInside the NaiveBayes#train method each document has common stop words removed using [NLTK](install http://www.nltk.org/install.html). The words have not yet been [stemmed](http://stackoverflow.com/questions/24647400/what-is-the-best-stemming-method-in-python) as this is a forthcoming feature.\n\nOnly the corpus of words are used as selectors to determine if an email is spam or ham. \n\nTo prevent words with 0 frequency from miscontruing the results, Laplace smoothing is applied to increment each 0 frequency word to 1.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Florenanicole%2Fpython-naive-bayes-spam-classifier","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Florenanicole%2Fpython-naive-bayes-spam-classifier","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Florenanicole%2Fpython-naive-bayes-spam-classifier/lists"}