{"id":18638485,"url":"https://github.com/takp/naive-bayes-sample","last_synced_at":"2025-11-04T16:30:19.243Z","repository":{"id":23587164,"uuid":"26955568","full_name":"takp/naive-bayes-sample","owner":"takp","description":"Infer the category of the document written in Japanese","archived":false,"fork":false,"pushed_at":"2014-11-21T14:43:19.000Z","size":120,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-27T09:27:57.415Z","etag":null,"topics":["naive-bayes","naive-bayes-algorithm"],"latest_commit_sha":null,"homepage":null,"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/takp.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":"2014-11-21T10:19:17.000Z","updated_at":"2020-03-01T01:22:38.000Z","dependencies_parsed_at":"2022-08-22T03:10:16.488Z","dependency_job_id":null,"html_url":"https://github.com/takp/naive-bayes-sample","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/takp%2Fnaive-bayes-sample","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/takp%2Fnaive-bayes-sample/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/takp%2Fnaive-bayes-sample/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/takp%2Fnaive-bayes-sample/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/takp","download_url":"https://codeload.github.com/takp/naive-bayes-sample/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239436026,"owners_count":19638247,"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":["naive-bayes","naive-bayes-algorithm"],"created_at":"2024-11-07T05:41:59.453Z","updated_at":"2025-11-04T16:30:19.208Z","avatar_url":"https://github.com/takp.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# naive-bayes-sample\n\nNaive Bayes sample program.\n\ninfer the category of the document. \n\n### Before Run\n\nIt's needed to install the \"BeautifuSoup\" : http://www.crummy.com/software/BeautifulSoup/\n\nThis App using \"Yahoo morphological analysis API\".\nhttp://developer.yahoo.co.jp/webapi/jlp/ma/v1/parse.html\n\nIf you want to use in English, please modify the 'morphological.py'.\n\n### Run\n\n\t$ python naivebayes.py\n\n### Reference\n\nhttp://gihyo.jp/dev/serial/01/machine-learning/0003?page=1\n\n### Naive Bayes\n\n\tP(cat, doc) = P(cat|doc)P(doc) = P(doc|cat)P(cat)\n\n\t=\u003e P(cat|doc) = P(doc|cat)P(cat) / P(doc)\n\nnow, we can get the P(cat|doc) by calculationg (1) P(doc|cat) and (2) P(cat).\n\n(1) P(doc|cat)\n\n\tp(doc|cat) = P(word1|cat)P(word2|cat)...P(wordn|cat)\n\nBy the assumption of independence, it is possible to approximate to this function, as documents is the aggregation of the words.\n\n\tP(word|cat) = ( number of word shows up in the category ) / ( number of all words )\n\n(2) P(cat)\n\n\tP(cat) = ( number of (this) category shows up (in train data) ) / ( number of all train data )\n\n* Using Logarithm\n\nIt is needed to use logarithm because the value of every P() is so small that it may cause Underflow.\n\nSo we convert the multiply to sum of logs.\n\n\tP(doc|cat)P(cat)\n\t= P(word1|cat)P(word2|cat)...P(wordn|cat)P(cat)\n\t= log P(word1|cat) + log P(word2|cat) + ... + log P(wordn|cat) + log P(cat)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftakp%2Fnaive-bayes-sample","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftakp%2Fnaive-bayes-sample","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftakp%2Fnaive-bayes-sample/lists"}