{"id":15493522,"url":"https://github.com/sinclairzx81/bayes","last_synced_at":"2026-06-04T23:31:06.859Z","repository":{"id":66034979,"uuid":"62276458","full_name":"sinclairzx81/bayes","owner":"sinclairzx81","description":"An implementation of a naive bayes classifier in TypeScript","archived":false,"fork":false,"pushed_at":"2017-08-20T23:26:21.000Z","size":16,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-19T11:12:37.221Z","etag":null,"topics":["machine-learning","naive-bayes"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sinclairzx81.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-06-30T03:30:08.000Z","updated_at":"2024-06-24T06:43:01.000Z","dependencies_parsed_at":null,"dependency_job_id":"81865e77-25fc-45f8-8728-9129e0607d7f","html_url":"https://github.com/sinclairzx81/bayes","commit_stats":{"total_commits":11,"total_committers":1,"mean_commits":11.0,"dds":0.0,"last_synced_commit":"0f79aafafdcde9a91b7167af6cdcab5df69fa4dd"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sinclairzx81%2Fbayes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sinclairzx81%2Fbayes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sinclairzx81%2Fbayes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sinclairzx81%2Fbayes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sinclairzx81","download_url":"https://codeload.github.com/sinclairzx81/bayes/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240887287,"owners_count":19873533,"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":["machine-learning","naive-bayes"],"created_at":"2024-10-02T08:07:47.863Z","updated_at":"2026-06-04T23:31:06.774Z","avatar_url":"https://github.com/sinclairzx81.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# bayes\n\nA naive bayes classifier written in typescript. This classifier was written specifically to support streaming large amounts of dynamic training data\n(given in the form of plain javascript objects) in real-time. This classifier is able to learn new features at random, and can be trained with\nnon structured javascript objects of varying properties. The classifier runs with a low memory footprint, and persisting training data is \nstraight forward.\n\nUseful for enabling classification services in real-time message based systems.\n\n## build\n```\nnpm install typescript -g\ntsc bayes.ts \n```\n\n## training\n\nIn the following example, we train the classifier with a basic weather dataset. The classifier is passed a series \nof training samples as javascript objects.\n\nnote: this algorithm only supports quantized attribute values, and not continuous numeric values such as integers/floats etc. \nIf using this library, you can encode your numerical data as strings. For example, instead of passing the number '25', you can quantize\nthis value as \"between 20 and 30\". \n\n```javascript\nlet classifier = new NaiveBayes()\nclassifier.train({ outlook: \"rainy\",    temp: \"hot\",  humidity: \"high\",   windy: \"no\",  play_golf: \"no\" })\nclassifier.train({ outlook: \"rainy\",    temp: \"hot\",  humidity: \"high\",   windy: \"yes\", play_golf: \"no\" })\nclassifier.train({ outlook: \"overcast\", temp: \"hot\",  humidity: \"high\",   windy: \"no\",  play_golf: \"yes\"})\nclassifier.train({ outlook: \"sunny\",    temp: \"mild\", humidity: \"high\",   windy: \"no\",  play_golf: \"yes\"})\nclassifier.train({ outlook: \"sunny\",    temp: \"cool\", humidity: \"normal\", windy: \"no\",  play_golf: \"yes\"})\nclassifier.train({ outlook: \"sunny\",    temp: \"cool\", humidity: \"normal\", windy: \"yes\", play_golf: \"no\" })\nclassifier.train({ outlook: \"overcast\", temp: \"cool\", humidity: \"normal\", windy: \"yes\", play_golf: \"yes\"})\nclassifier.train({ outlook: \"rainy\",    temp: \"mild\", humidity: \"high\",   windy: \"no\",  play_golf: \"no\" })\nclassifier.train({ outlook: \"rainy\",    temp: \"cool\", humidity: \"normal\", windy: \"no\",  play_golf: \"yes\"})\nclassifier.train({ outlook: \"sunny\",    temp: \"mild\", humidity: \"normal\", windy: \"no\",  play_golf: \"yes\"})\nclassifier.train({ outlook: \"rainy\",    temp: \"mild\", humidity: \"normal\", windy: \"yes\", play_golf: \"yes\"})\nclassifier.train({ outlook: \"overcast\", temp: \"mild\", humidity: \"high\",   windy: \"yes\", play_golf: \"yes\"})\nclassifier.train({ outlook: \"overcast\", temp: \"hot\",  humidity: \"normal\", windy: \"no\",  play_golf: \"yes\"})\nclassifier.train({ outlook: \"sunny\",    temp: \"mild\", humidity: \"high\",   windy: \"yes\", play_golf: \"no\" })\n```\n## classification / prediction\n\nOnce the classifier has been trained, it then becomes possible to classify features.\n\n### playing golf today\n\nasks the likelyhood of playing golf with these conditions.\n\n```\nlet p = classifier.classify(\"play_golf\", {\n  outlook : \"sunny\",\n  temp    : \"cool\",\n  humidity: \"high\",\n  windy   : \"yes\",\n})\n// p = { no : 0.2285714285714286, \n//       yes: 0.7714285714285715 }\n```\n### weather outlook based on humidity\n\nclassifies the weather outlook based on only the humidity. other features are ignored in classification.\n\n```\nlet p = classifier.classify(\"outlook\", { \n  humidity: \"high\" \n}) \n// p = { rainy    : 0.4285714285714286, \n//       overcast : 0.28571428571428575, \n//       sunny    : 0.28571428571428575 }\n```\n\n### probability distribution\n\nobtain a features probability distribution, ignoring all other features.\n\n```\nlet p = classifier.classify(\"temp\")\n\n// p = { hot  : 0.2857142857142857,\n//       mild : 0.42857142857142855,\n//       cool : 0.2857142857142857 }\n```\n\n## persisting training data\n\nIts possible to persist training data by saving the classifiers state.\n\n``` javascript\n  let state = classifier.state\n\n  // save state as json...which can be loaded with...\n\n  let classifier = new NaiveBayes(state)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsinclairzx81%2Fbayes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsinclairzx81%2Fbayes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsinclairzx81%2Fbayes/lists"}