{"id":13413342,"url":"https://github.com/jbrukh/bayesian","last_synced_at":"2025-12-17T00:54:28.355Z","repository":{"id":1906068,"uuid":"2833211","full_name":"jbrukh/bayesian","owner":"jbrukh","description":"Naive Bayesian Classification for Golang.","archived":false,"fork":false,"pushed_at":"2023-11-17T14:32:45.000Z","size":73,"stargazers_count":796,"open_issues_count":8,"forks_count":128,"subscribers_count":34,"default_branch":"master","last_synced_at":"2024-07-31T20:52:14.882Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","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/jbrukh.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":"2011-11-23T04:17:00.000Z","updated_at":"2024-07-26T23:47:20.000Z","dependencies_parsed_at":"2024-06-18T12:19:54.948Z","dependency_job_id":"f17ba411-a486-4135-b83a-aa1192be4799","html_url":"https://github.com/jbrukh/bayesian","commit_stats":{"total_commits":78,"total_committers":15,"mean_commits":5.2,"dds":0.4358974358974359,"last_synced_commit":"13ae6f916c7a0fb3d552ec05b8bd7f32902b7125"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jbrukh%2Fbayesian","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jbrukh%2Fbayesian/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jbrukh%2Fbayesian/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jbrukh%2Fbayesian/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jbrukh","download_url":"https://codeload.github.com/jbrukh/bayesian/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221498731,"owners_count":16833055,"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":[],"created_at":"2024-07-30T20:01:38.212Z","updated_at":"2025-12-17T00:54:28.347Z","avatar_url":"https://github.com/jbrukh.png","language":"Go","readme":"# Naive Bayesian Classification\n\n[![Go Reference](https://pkg.go.dev/badge/github.com/jbrukh/bayesian.svg)](https://pkg.go.dev/github.com/jbrukh/bayesian)\n[![Go Version](https://img.shields.io/github/go-mod/go-version/jbrukh/bayesian)](https://go.dev/)\n[![License](https://img.shields.io/badge/license-BSD--3--Clause-blue.svg)](LICENSE)\n\nPerform naive Bayesian classification into an arbitrary number of classes on sets of strings. `bayesian` also supports term frequency-inverse document frequency calculations ([TF-IDF](https://www.wikiwand.com/en/Tf%E2%80%93idf)).\n\nCopyright (c) 2011-2024. Jake Brukhman. (jbrukh@gmail.com).\nAll rights reserved.  See the LICENSE file for BSD-style license.\n\n------------\n\n## Background\n\nThis is meant to be an low-entry barrier Go library for basic Bayesian classification. See code comments for a refresher on naive Bayesian classifiers, and please take some time to understand underflow edge cases as this otherwise may result in innacurate classifications.\n\n------------\n\n## Installation\n\nUsing the go command:\n\n```shell\ngo get github.com/jbrukh/bayesian\ngo install !$\n```\n\n------------\n\n## Documentation\n\nSee the documentation on [pkg.go.dev](https://pkg.go.dev/github.com/jbrukh/bayesian).\n\n------------\n\n## Features\n\n- Conditional probability and \"log-likelihood\"-like scoring.\n- Underflow detection.\n- Simple persistence of classifiers.\n- Statistics.\n- TF-IDF support.\n\n------------\n\n## Example 1 (Simple Classification)\n\nTo use the classifier, first you must create some classes\nand train it:\n\n```go\nimport \"github.com/jbrukh/bayesian\"\n\nconst (\n    Good bayesian.Class = \"Good\"\n    Bad  bayesian.Class = \"Bad\"\n)\n\nclassifier := bayesian.NewClassifier(Good, Bad)\ngoodStuff := []string{\"tall\", \"rich\", \"handsome\"}\nbadStuff  := []string{\"poor\", \"smelly\", \"ugly\"}\nclassifier.Learn(goodStuff, Good)\nclassifier.Learn(badStuff,  Bad)\n```\n\nThen you can ascertain the scores of each class and\nthe most likely class your data belongs to:\n\n```go\nscores, likely, _ := classifier.LogScores(\n                        []string{\"tall\", \"girl\"},\n                     )\n```\n\nMagnitude of the score indicates likelihood. Alternatively (but\nwith some risk of float underflow), you can obtain actual probabilities:\n\n```go\nprobs, likely, _ := classifier.ProbScores(\n                        []string{\"tall\", \"girl\"},\n                     )\n```\n\n## Example 2 (TF-IDF Support)\n\nTo use the TF-IDF classifier, first you must create some classes\nand train it and you need to call ConvertTermsFreqToTfIdf() AFTER training\nand before calling classification methods such as `LogScores`, `SafeProbScores`, and `ProbScores`)\n\n```go\nimport \"github.com/jbrukh/bayesian\"\n\nconst (\n    Good bayesian.Class = \"Good\"\n    Bad bayesian.Class = \"Bad\"\n)\n\n// Create a classifier with TF-IDF support.\nclassifier := bayesian.NewClassifierTfIdf(Good, Bad)\n\ngoodStuff := []string{\"tall\", \"rich\", \"handsome\"}\nbadStuff  := []string{\"poor\", \"smelly\", \"ugly\"}\n\nclassifier.Learn(goodStuff, Good)\nclassifier.Learn(badStuff,  Bad)\n\n// Required\nclassifier.ConvertTermsFreqToTfIdf()\n```\n\nThen you can ascertain the scores of each class and\nthe most likely class your data belongs to:\n\n```go\nscores, likely, _ := classifier.LogScores(\n    []string{\"tall\", \"girl\"},\n)\n```\n\nMagnitude of the score indicates likelihood. Alternatively (but\nwith some risk of float underflow), you can obtain actual probabilities:\n\n```go\nprobs, likely, _ := classifier.ProbScores(\n    []string{\"tall\", \"girl\"},\n)\n```\n\nUse wisely.\n","funding_links":[],"categories":["Bayesian Classifiers","Machine Learning","others","Go","\u003cspan id=\"机器学习-machine-learning\"\u003e机器学习 Machine Learning\u003c/span\u003e","机器学习","[](https://github.com/josephmisiti/awesome-machine-learning/blob/master/README.md#go)Go","機器學習","Relational Databases"],"sub_categories":["Vector Database","Advanced Console UIs","\u003cspan id=\"高级控制台用户界面-advanced-console-uis\"\u003e高级控制台用户界面 Advanced Console UIs\u003c/span\u003e","SQL 查询语句构建库","Search and Analytic Databases","Tools","[Tools](#tools-1)","Speech Recognition","检索及分析资料库","Middlewares","高級控制台界面","交流","高级控制台界面"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjbrukh%2Fbayesian","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjbrukh%2Fbayesian","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjbrukh%2Fbayesian/lists"}