{"id":16653198,"url":"https://github.com/anuraganalog/navie-bayes","last_synced_at":"2026-04-19T20:38:13.933Z","repository":{"id":56513331,"uuid":"309259398","full_name":"AnuragAnalog/Navie-Bayes","owner":"AnuragAnalog","description":"Implemented Gaussian Naive Bayes Classifier from scratch","archived":false,"fork":false,"pushed_at":"2020-11-21T14:50:45.000Z","size":26367,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-12-26T09:34:41.785Z","etag":null,"topics":["bayes","classifier","dataset","datasets","gaussian","guassian-naive-bayes","iris","multinomial-naive-bayes","naive","naive-bayes-classifiers","numpy","py","scratch"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AnuragAnalog.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-11-02T04:39:45.000Z","updated_at":"2021-05-11T07:12:55.000Z","dependencies_parsed_at":"2022-08-15T20:10:27.229Z","dependency_job_id":null,"html_url":"https://github.com/AnuragAnalog/Navie-Bayes","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/AnuragAnalog/Navie-Bayes","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AnuragAnalog%2FNavie-Bayes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AnuragAnalog%2FNavie-Bayes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AnuragAnalog%2FNavie-Bayes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AnuragAnalog%2FNavie-Bayes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AnuragAnalog","download_url":"https://codeload.github.com/AnuragAnalog/Navie-Bayes/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AnuragAnalog%2FNavie-Bayes/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32022554,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-18T20:23:30.271Z","status":"online","status_checked_at":"2026-04-19T02:00:07.110Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["bayes","classifier","dataset","datasets","gaussian","guassian-naive-bayes","iris","multinomial-naive-bayes","naive","naive-bayes-classifiers","numpy","py","scratch"],"created_at":"2024-10-12T09:43:29.557Z","updated_at":"2026-04-19T20:38:13.913Z","avatar_url":"https://github.com/AnuragAnalog.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Naive Bayes Classifiers\n\nThe file `naivebayes.py` contanins the implementation Guassian and Multinomail Naive Bayes Classifier\n\nTo make it much more simple I have restricted the input domain only to numpy arrays.\n\n![formula](./formula.png)\n\n## Gaussian Naive Bayes\n\nThe formula is used compute the posterior probability, in Guassian Naive Bayes for calculating the Likelihood we use the normal uni/multivariate distribution(depending on the features)\n\n```python3\nself.n_features_ # Number of features\n\nself.n_classes_ # Number of classes\n\nself.class_mean_ # Contains the class mean's\n\nself.class_std_ # Contains the class standard deviation's\n\nself.prior_proba_ # Prior Probabilities of each class\n\nself.class_encoding_ # Contains Class encodings\n```\n\n### Example using Iris dataset\n\n```ipython\nIn [1]: import pandas as pd                                            \n\nIn [2]: from naivebayes import GaussianNB                              \n\nIn [3]: from sklearn.model_selection import train_test_split           \n\nIn [4]: data = pd.read_csv('Iris.csv', index_col='Id')\n\nIn [5]: train_X, test_X, train_y, test_y = train_test_split(data.loc[:, data.columns != 'Species'], data['Species'], test_size=0.2)            \n\nIn [6]: clf = GaussianNB()\n\nIn [7]: clf.fit(train_X.values, train_y.values)                                                                                               \n\nIn [8]: clf.predict(test_X.values)\nOut[8]: array([2, 2, 0, 1, 1, 2, 0, 0, 0, 2, 0, 2, 1, 1, 2, 1, 1, 0, 1, 1, 2, 0, 0, 2, 1, 0, 2, 0, 0, 0])\n\nIn [9]: clf.evaluate(train_X.values, train_y.values) # R^2 score on training data         \nOut[9]: 0.9248747913188647\n\nIn [10]: clf.evaluate(test_X.values, test_y.values) # R^2 score on testing data             \nOut[10]: 0.9486301369863014\n```\n\n\u003e Change the data reading according to your dataset file.\n\n## Multinomial Naive Bayes\n\nThe above figure refers to the Multinomial Naive Bayes formula.\n\n```python3\nself.n_features_ # Number of features\n\nself.n_classes_ # Number of classes\n\nself.prior_proba_ # Prior Probabilities of each class\n\nself.class_encoding_ # Contains Class encodings\n```\n\n### Example using IMDB dataset\n\n```ipython\nIn [1]: import pandas as pd                                            \n\nIn [2]: from naivebayes import MultinomialNB                              \n\nIn [3]: from sklearn.model_selection import train_test_split           \n\nIn [4]: data = pd.read_csv('imdb.zip', compression='zip')\n\nIn [5]: train_X, test_X, train_y, test_y = train_test_split(data.loc[:, data.columns != 'sentiment'], data['sentiment'], test_size=0.2)            \n\nIn [6]: clf = MultinomialNB()\n\nIn [7]: clf.fit(train_X.values, train_y.values)\n\nIn [8]: clf.predict(test_X.values)\nOut[8]: array([0 0 0 ... 1 0 0])\n\nIn [9]: clf.evaluate(train_X.values, train_y.values) # MSE on training data         \nOut[9]: 0.4501\n\nIn [10]: clf.evaluate(test_X.values, test_y.values) # MSE on testing data             \nOut[10]: 0.4517\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanuraganalog%2Fnavie-bayes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanuraganalog%2Fnavie-bayes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanuraganalog%2Fnavie-bayes/lists"}