{"action":"created","comment":{"url":"https://api.github.com/repos/jbrukh/bayesian/pulls/comments/76110542","id":76110542,"diff_hunk":"@@ -243,3 +243,115 @@ func TestFreqMatrixConstruction(t *testing.T) {\n \t\t}\n \t}\n }\n+\n+func TestTfIdClassifier_SanityChecks(t *testing.T) {\n+\tc := NewClassifierTFIDF(Good, Bad)\n+\tAssert(t, c.IsTfIdf() == true)\n+\n+\tc.Learn([]string{\"tall\", \"handsome\", \"rich\"}, Good)\n+\n+\tdefer func() {\n+\t\tif err := recover(); err != nil {\n+\t\t\t// we are good\n+\t\t}\n+\t}()\n+\tc.LogScores([]string{\"a\", \"b\", \"c\"})\n+\tAssert(t, false, \"Should have panicked:Need to run ConvertTermsFreqToTFIDF() first..\", c)\n+\n+}\n+\n+func TestTfIdClassifier_Tf_Checks(t *testing.T) {\n+\tc := NewClassifierTFIDF(Good, Bad)\n+\tAssert(t, c.IsTfIdf() == true)\n+\n+\tc.Learn([]string{\"tall\", \"handsome\", \"rich\"}, Good)\n+\tc.Learn([]string{\"tall\", \"blonde\"}, Good)\n+\tc.Learn([]string{\"tall\"}, Good)\n+\n+\tdata := c.datas[Good]\n+\t// Total words seen in training.\n+\tAssert(t, data.Total == 6)\n+\n+\t// Plain old counts for words.\n+\tAssert(t, data.Freqs[\"tall\"] == 3)\n+\tAssert(t, data.Freqs[\"blonde\"] == 1)\n+\n+\t// Check for term frequency's per 'document' (tall)\n+\tAssert(t, data.FreqTfs[\"tall\"][0] == float64(0.3333333333333333))\n+\tAssert(t, data.FreqTfs[\"tall\"][1] == float64(0.5))\n+\tAssert(t, data.FreqTfs[\"tall\"][2] == float64(1))\n+\n+\t// Check for term frequency's per 'document' (blonde)\n+\tAssert(t, data.FreqTfs[\"blonde\"][0] == float64(0.5))\n+\n+}\n+\n+func TestTfIdClassifier_ConvertToTfIdf(t *testing.T) {\n+\tc := NewClassifierTFIDF(Good, Bad)\n+\tAssert(t, c.IsTfIdf() == true)\n+\n+\tc.Learn([]string{\"tall\", \"handsome\", \"rich\"}, Good)\n+\tc.Learn([]string{\"tall\", \"blonde\"}, Good)\n+\tc.Learn([]string{\"tall\"}, Good)\n+\n+\t// Now we convert the TF's to Tf/Idf\n+\t// We can only this after we have learned all the documents and classes.\n+\t// We can add more learning afterwards but need to call ConvertToTfIdf() again before\n+\t// we can predict classes.\n+\tc.ConvertTermsFreqToTFIDF()\n+\n+\tdata := c.datas[Good]\n+\n+\t// Tf-Idf after we have converted the tf's\n+\tAssert(t, data.Freqs[\"tall\"] == float64(0.5620939930012151))\n+\tAssert(t, data.Freqs[\"blonde\"] == float64(0.16440195389316542))\n+\tAssert(t, data.Freqs[\"notseen\"] == float64(0))\n+\tAssert(t, data.FreqTfs[\"tall\"][0] == float64(0.11664504260744213))\n+\tAssert(t, data.FreqTfs[\"tall\"][1] == float64(0.16440195389316542))\n+\tAssert(t, data.FreqTfs[\"tall\"][2] == float64(0.28104699650060755))\n+\n+}\n+\n+func TestTfIdClassifier_CheckForDoubleConvert(t *testing.T) {\n+\n+\tc := NewClassifierTFIDF(Good, Bad)\n+\tAssert(t, c.IsTfIdf() == true)\n+\n+\tc.Learn([]string{\"tall\", \"handsome\", \"rich\"}, Good)\n+\tc.Learn([]string{\"tall\", \"blonde\"}, Good)\n+\tc.Learn([]string{\"tall\"}, Good)\n+\n+\t// We can only call ConverToTdfIdf once per learning cycle (cumulative counts).\n+\tc.ConvertTermsFreqToTFIDF()","path":"bayesian_test.go","position":83,"original_position":83,"commit_id":"a6abeff30a2359ff408d2c7c7ac7b440bb36f343","original_commit_id":"2376d16b671379494cd51477bb6c02c4c6e464e6","user":{"login":"jbrukh","id":44650,"avatar_url":"https://avatars.githubusercontent.com/u/44650?v=3","gravatar_id":"","url":"https://api.github.com/users/jbrukh","html_url":"https://github.com/jbrukh","followers_url":"https://api.github.com/users/jbrukh/followers","following_url":"https://api.github.com/users/jbrukh/following{/other_user}","gists_url":"https://api.github.com/users/jbrukh/gists{/gist_id}","starred_url":"https://api.github.com/users/jbrukh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jbrukh/subscriptions","organizations_url":"https://api.github.com/users/jbrukh/orgs","repos_url":"https://api.github.com/users/jbrukh/repos","events_url":"https://api.github.com/users/jbrukh/events{/privacy}","received_events_url":"https://api.github.com/users/jbrukh/received_events","type":"User","site_admin":false},"body":"Update function call, as above.","created_at":"2016-08-24T18:18:44Z","updated_at":"2016-08-24T18:18:44Z","html_url":"https://github.com/jbrukh/bayesian/pull/14#discussion_r76110542","pull_request_url":"https://api.github.com/repos/jbrukh/bayesian/pulls/14","_links":{"self":{"href":"https://api.github.com/repos/jbrukh/bayesian/pulls/comments/76110542"},"html":{"href":"https://github.com/jbrukh/bayesian/pull/14#discussion_r76110542"},"pull_request":{"href":"https://api.github.com/repos/jbrukh/bayesian/pulls/14"}}},"pull_request":{"url":"https://api.github.com/repos/jbrukh/bayesian/pulls/14","id":77791150,"html_url":"https://github.com/jbrukh/bayesian/pull/14","diff_url":"https://github.com/jbrukh/bayesian/pull/14.diff","patch_url":"https://github.com/jbrukh/bayesian/pull/14.patch","issue_url":"https://api.github.com/repos/jbrukh/bayesian/issues/14","number":14,"state":"open","locked":false,"title":"Initial TD-IDF work","user":{"login":"rawoke083","id":5529508,"avatar_url":"https://avatars.githubusercontent.com/u/5529508?v=3","gravatar_id":"","url":"https://api.github.com/users/rawoke083","html_url":"https://github.com/rawoke083","followers_url":"https://api.github.com/users/rawoke083/followers","following_url":"https://api.github.com/users/rawoke083/following{/other_user}","gists_url":"https://api.github.com/users/rawoke083/gists{/gist_id}","starred_url":"https://api.github.com/users/rawoke083/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rawoke083/subscriptions","organizations_url":"https://api.github.com/users/rawoke083/orgs","repos_url":"https://api.github.com/users/rawoke083/repos","events_url":"https://api.github.com/users/rawoke083/events{/privacy}","received_events_url":"https://api.github.com/users/rawoke083/received_events","type":"User","site_admin":false},"body":"Added in TD-IDF support to use instead of plain word counts ! Works very well ! Lots of extra accuracy.\r\nSee updated README for usage.\r\n ","created_at":"2016-07-18T11:08:52Z","updated_at":"2016-08-24T18:18:44Z","closed_at":null,"merged_at":null,"merge_commit_sha":"784c26e64d033a1f6f0b83fadeb9db2860d1b9dc","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/jbrukh/bayesian/pulls/14/commits","review_comments_url":"https://api.github.com/repos/jbrukh/bayesian/pulls/14/comments","review_comment_url":"https://api.github.com/repos/jbrukh/bayesian/pulls/comments{/number}","comments_url":"https://api.github.com/repos/jbrukh/bayesian/issues/14/comments","statuses_url":"https://api.github.com/repos/jbrukh/bayesian/statuses/a6abeff30a2359ff408d2c7c7ac7b440bb36f343","head":{"label":"rawoke083:master","ref":"master","sha":"a6abeff30a2359ff408d2c7c7ac7b440bb36f343","user":{"login":"rawoke083","id":5529508,"avatar_url":"https://avatars.githubusercontent.com/u/5529508?v=3","gravatar_id":"","url":"https://api.github.com/users/rawoke083","html_url":"https://github.com/rawoke083","followers_url":"https://api.github.com/users/rawoke083/followers","following_url":"https://api.github.com/users/rawoke083/following{/other_user}","gists_url":"https://api.github.com/users/rawoke083/gists{/gist_id}","starred_url":"https://api.github.com/users/rawoke083/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rawoke083/subscriptions","organizations_url":"https://api.github.com/users/rawoke083/orgs","repos_url":"https://api.github.com/users/rawoke083/repos","events_url":"https://api.github.com/users/rawoke083/events{/privacy}","received_events_url":"https://api.github.com/users/rawoke083/received_events","type":"User","site_admin":false},"repo":{"id":63584436,"name":"bayesian","full_name":"rawoke083/bayesian","owner":{"login":"rawoke083","id":5529508,"avatar_url":"https://avatars.githubusercontent.com/u/5529508?v=3","gravatar_id":"","url":"https://api.github.com/users/rawoke083","html_url":"https://github.com/rawoke083","followers_url":"https://api.github.com/users/rawoke083/followers","following_url":"https://api.github.com/users/rawoke083/following{/other_user}","gists_url":"https://api.github.com/users/rawoke083/gists{/gist_id}","starred_url":"https://api.github.com/users/rawoke083/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rawoke083/subscriptions","organizations_url":"https://api.github.com/users/rawoke083/orgs","repos_url":"https://api.github.com/users/rawoke083/repos","events_url":"https://api.github.com/users/rawoke083/events{/privacy}","received_events_url":"https://api.github.com/users/rawoke083/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/rawoke083/bayesian","description":"Naive Bayesian Classification for Golang.","fork":true,"url":"https://api.github.com/repos/rawoke083/bayesian","forks_url":"https://api.github.com/repos/rawoke083/bayesian/forks","keys_url":"https://api.github.com/repos/rawoke083/bayesian/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rawoke083/bayesian/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rawoke083/bayesian/teams","hooks_url":"https://api.github.com/repos/rawoke083/bayesian/hooks","issue_events_url":"https://api.github.com/repos/rawoke083/bayesian/issues/events{/number}","events_url":"https://api.github.com/repos/rawoke083/bayesian/events","assignees_url":"https://api.github.com/repos/rawoke083/bayesian/assignees{/user}","branches_url":"https://api.github.com/repos/rawoke083/bayesian/branches{/branch}","tags_url":"https://api.github.com/repos/rawoke083/bayesian/tags","blobs_url":"https://api.github.com/repos/rawoke083/bayesian/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rawoke083/bayesian/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rawoke083/bayesian/git/refs{/sha}","trees_url":"https://api.github.com/repos/rawoke083/bayesian/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rawoke083/bayesian/statuses/{sha}","languages_url":"https://api.github.com/repos/rawoke083/bayesian/languages","stargazers_url":"https://api.github.com/repos/rawoke083/bayesian/stargazers","contributors_url":"https://api.github.com/repos/rawoke083/bayesian/contributors","subscribers_url":"https://api.github.com/repos/rawoke083/bayesian/subscribers","subscription_url":"https://api.github.com/repos/rawoke083/bayesian/subscription","commits_url":"https://api.github.com/repos/rawoke083/bayesian/commits{/sha}","git_commits_url":"https://api.github.com/repos/rawoke083/bayesian/git/commits{/sha}","comments_url":"https://api.github.com/repos/rawoke083/bayesian/comments{/number}","issue_comment_url":"https://api.github.com/repos/rawoke083/bayesian/issues/comments{/number}","contents_url":"https://api.github.com/repos/rawoke083/bayesian/contents/{+path}","compare_url":"https://api.github.com/repos/rawoke083/bayesian/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rawoke083/bayesian/merges","archive_url":"https://api.github.com/repos/rawoke083/bayesian/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rawoke083/bayesian/downloads","issues_url":"https://api.github.com/repos/rawoke083/bayesian/issues{/number}","pulls_url":"https://api.github.com/repos/rawoke083/bayesian/pulls{/number}","milestones_url":"https://api.github.com/repos/rawoke083/bayesian/milestones{/number}","notifications_url":"https://api.github.com/repos/rawoke083/bayesian/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rawoke083/bayesian/labels{/name}","releases_url":"https://api.github.com/repos/rawoke083/bayesian/releases{/id}","deployments_url":"https://api.github.com/repos/rawoke083/bayesian/deployments","created_at":"2016-07-18T08:31:51Z","updated_at":"2016-07-18T08:31:52Z","pushed_at":"2016-08-24T18:15:42Z","git_url":"git://github.com/rawoke083/bayesian.git","ssh_url":"git@github.com:rawoke083/bayesian.git","clone_url":"https://github.com/rawoke083/bayesian.git","svn_url":"https://github.com/rawoke083/bayesian","homepage":"","size":49,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"jbrukh:master","ref":"master","sha":"a65fd1effddb7bd71c6bb6ca1876e045a7aeac6e","user":{"login":"jbrukh","id":44650,"avatar_url":"https://avatars.githubusercontent.com/u/44650?v=3","gravatar_id":"","url":"https://api.github.com/users/jbrukh","html_url":"https://github.com/jbrukh","followers_url":"https://api.github.com/users/jbrukh/followers","following_url":"https://api.github.com/users/jbrukh/following{/other_user}","gists_url":"https://api.github.com/users/jbrukh/gists{/gist_id}","starred_url":"https://api.github.com/users/jbrukh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jbrukh/subscriptions","organizations_url":"https://api.github.com/users/jbrukh/orgs","repos_url":"https://api.github.com/users/jbrukh/repos","events_url":"https://api.github.com/users/jbrukh/events{/privacy}","received_events_url":"https://api.github.com/users/jbrukh/received_events","type":"User","site_admin":false},"repo":{"id":2833211,"name":"bayesian","full_name":"jbrukh/bayesian","owner":{"login":"jbrukh","id":44650,"avatar_url":"https://avatars.githubusercontent.com/u/44650?v=3","gravatar_id":"","url":"https://api.github.com/users/jbrukh","html_url":"https://github.com/jbrukh","followers_url":"https://api.github.com/users/jbrukh/followers","following_url":"https://api.github.com/users/jbrukh/following{/other_user}","gists_url":"https://api.github.com/users/jbrukh/gists{/gist_id}","starred_url":"https://api.github.com/users/jbrukh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jbrukh/subscriptions","organizations_url":"https://api.github.com/users/jbrukh/orgs","repos_url":"https://api.github.com/users/jbrukh/repos","events_url":"https://api.github.com/users/jbrukh/events{/privacy}","received_events_url":"https://api.github.com/users/jbrukh/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jbrukh/bayesian","description":"Naive Bayesian Classification for Golang.","fork":false,"url":"https://api.github.com/repos/jbrukh/bayesian","forks_url":"https://api.github.com/repos/jbrukh/bayesian/forks","keys_url":"https://api.github.com/repos/jbrukh/bayesian/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jbrukh/bayesian/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jbrukh/bayesian/teams","hooks_url":"https://api.github.com/repos/jbrukh/bayesian/hooks","issue_events_url":"https://api.github.com/repos/jbrukh/bayesian/issues/events{/number}","events_url":"https://api.github.com/repos/jbrukh/bayesian/events","assignees_url":"https://api.github.com/repos/jbrukh/bayesian/assignees{/user}","branches_url":"https://api.github.com/repos/jbrukh/bayesian/branches{/branch}","tags_url":"https://api.github.com/repos/jbrukh/bayesian/tags","blobs_url":"https://api.github.com/repos/jbrukh/bayesian/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jbrukh/bayesian/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jbrukh/bayesian/git/refs{/sha}","trees_url":"https://api.github.com/repos/jbrukh/bayesian/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jbrukh/bayesian/statuses/{sha}","languages_url":"https://api.github.com/repos/jbrukh/bayesian/languages","stargazers_url":"https://api.github.com/repos/jbrukh/bayesian/stargazers","contributors_url":"https://api.github.com/repos/jbrukh/bayesian/contributors","subscribers_url":"https://api.github.com/repos/jbrukh/bayesian/subscribers","subscription_url":"https://api.github.com/repos/jbrukh/bayesian/subscription","commits_url":"https://api.github.com/repos/jbrukh/bayesian/commits{/sha}","git_commits_url":"https://api.github.com/repos/jbrukh/bayesian/git/commits{/sha}","comments_url":"https://api.github.com/repos/jbrukh/bayesian/comments{/number}","issue_comment_url":"https://api.github.com/repos/jbrukh/bayesian/issues/comments{/number}","contents_url":"https://api.github.com/repos/jbrukh/bayesian/contents/{+path}","compare_url":"https://api.github.com/repos/jbrukh/bayesian/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jbrukh/bayesian/merges","archive_url":"https://api.github.com/repos/jbrukh/bayesian/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jbrukh/bayesian/downloads","issues_url":"https://api.github.com/repos/jbrukh/bayesian/issues{/number}","pulls_url":"https://api.github.com/repos/jbrukh/bayesian/pulls{/number}","milestones_url":"https://api.github.com/repos/jbrukh/bayesian/milestones{/number}","notifications_url":"https://api.github.com/repos/jbrukh/bayesian/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jbrukh/bayesian/labels{/name}","releases_url":"https://api.github.com/repos/jbrukh/bayesian/releases{/id}","deployments_url":"https://api.github.com/repos/jbrukh/bayesian/deployments","created_at":"2011-11-23T04:17:00Z","updated_at":"2016-08-18T10:30:18Z","pushed_at":"2016-08-24T18:15:42Z","git_url":"git://github.com/jbrukh/bayesian.git","ssh_url":"git@github.com:jbrukh/bayesian.git","clone_url":"https://github.com/jbrukh/bayesian.git","svn_url":"https://github.com/jbrukh/bayesian","homepage":"","size":46,"stargazers_count":353,"watchers_count":353,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":52,"mirror_url":null,"open_issues_count":3,"forks":52,"open_issues":3,"watchers":353,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/jbrukh/bayesian/pulls/14"},"html":{"href":"https://github.com/jbrukh/bayesian/pull/14"},"issue":{"href":"https://api.github.com/repos/jbrukh/bayesian/issues/14"},"comments":{"href":"https://api.github.com/repos/jbrukh/bayesian/issues/14/comments"},"review_comments":{"href":"https://api.github.com/repos/jbrukh/bayesian/pulls/14/comments"},"review_comment":{"href":"https://api.github.com/repos/jbrukh/bayesian/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/jbrukh/bayesian/pulls/14/commits"},"statuses":{"href":"https://api.github.com/repos/jbrukh/bayesian/statuses/a6abeff30a2359ff408d2c7c7ac7b440bb36f343"}}}}
{"actor":{"display_login":"jbrukh"}}