{"id":17358351,"url":"https://github.com/subhash3/naive-bayes-classifier","last_synced_at":"2025-08-03T20:33:34.319Z","repository":{"id":174674006,"uuid":"366953490","full_name":"Subhash3/Naive-Bayes-Classifier","owner":"Subhash3","description":"Naive Bayes Classifier in Typescript","archived":false,"fork":false,"pushed_at":"2021-05-13T16:43:04.000Z","size":112,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-25T20:02:54.894Z","etag":null,"topics":["machine-learning","naive-bayes-classifier","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/Subhash3.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}},"created_at":"2021-05-13T06:17:53.000Z","updated_at":"2021-05-21T05:31:33.000Z","dependencies_parsed_at":null,"dependency_job_id":"e7d7263c-d8df-46bf-b009-d1645f26349a","html_url":"https://github.com/Subhash3/Naive-Bayes-Classifier","commit_stats":null,"previous_names":["subhash3/naive-bayes-classifier"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Subhash3/Naive-Bayes-Classifier","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Subhash3%2FNaive-Bayes-Classifier","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Subhash3%2FNaive-Bayes-Classifier/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Subhash3%2FNaive-Bayes-Classifier/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Subhash3%2FNaive-Bayes-Classifier/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Subhash3","download_url":"https://codeload.github.com/Subhash3/Naive-Bayes-Classifier/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Subhash3%2FNaive-Bayes-Classifier/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268607810,"owners_count":24277628,"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","status":"online","status_checked_at":"2025-08-03T02:00:12.545Z","response_time":2577,"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":["machine-learning","naive-bayes-classifier","typescript"],"created_at":"2024-10-15T19:05:11.203Z","updated_at":"2025-08-03T20:33:34.310Z","avatar_url":"https://github.com/Subhash3.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Naive Bayes Classifer\n\n\n    Just trying to \"learn naive bayes classifer\"\n\n![alt text](https://github.com/Subhash3/Naive-Bayes-Classifer/blob/main/math.png?raw=true)\n\n### API\n```ts\n    /* Loads the dataset from a json file of data samples*/\n    loadDatasetFromFile(file: string);\n\n    /* Assign the dataset to be an array of pre-loaded samples*/\n    loadDataset(data: IFC_Iris_Data_Sample[]);\n\n    /* Computes the mean and standard deviation of  different features of each category */\n    train();\n\n    /* Computes the probability of each class given a new data sample by using bayes theorem */\n    predict(newSample: IFC_Iris_Data_Sample, returnProbabilities: boolean = false);\n\n    /* Loads the dataset from an array(array(strings)) \n        Something like this\n        [\n            [\"1.0\", \"3.2\", \"6.9\",    \"4.20\"],\n            [\"1.0\", \"3.2\", \"6.9\",    \"4.20\"],\n            [\"1.0\", \"3.2\", \"6.9\",    \"4.20\"],\n            \u003c--   Features   --\u003e \u003c- Category -\u003e\n        ]\n    */\n    loadDatasetFromArr(data: (string[])[]);\n```\n\n\n### How to run?\n```bash\n    # Install npm dependencies\n    git clone https://github.com/Subhash3/Naive-Bayes-Classifier\n    cd Naive-Bayes-Classifier\n    npm install\n\n    # Start\n    ts-node source/index.js\n\n    # Build: Compile ts to generate js files\n    npm run build # this creates a build/ folder with all the compiled (js) code\n```\n\n\n### Dataset format\n* A dataset is a list of data samples of the following interface\n```ts\ninterface IFC_Iris_Data_Sample {\n    features: number[],\n    category: string\n}\n\nEg:\ndataset = [\n    {\n        \"features\": [\n            3.393533211,\n            2.331273381\n        ],\n        \"category\": 0\n    },\n    {\n        \"features\": [\n            3.110073483,\n            1.781539638\n        ],\n        \"category\": 0\n    }\n]\n```\n\n### TODO\n    - [x] Loss Computation.\n    - [ ] Apply log to bayes chain to get rid of overflow errors.\n    - [ ] Document the code nicely in tsdoc format.\n    - [ ] Use a matrix of size mxn where m is the no.of categories and n is the number of features such that the location [i][j] contains the mean and standard deviation of ith feature, given class = j.\n    - [ ] Extend the classifier to text classification.\n\n#### Feel free to contribute and open any issues.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsubhash3%2Fnaive-bayes-classifier","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsubhash3%2Fnaive-bayes-classifier","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsubhash3%2Fnaive-bayes-classifier/lists"}