{"action":"created","comment":{"url":"https://api.github.com/repos/jmschrei/pomegranate/pulls/comments/53068675","id":53068675,"diff_hunk":"@@ -0,0 +1,108 @@\n+Naive Bayes Classifiers\n+=======================\n+\n+The Naive Bayes classifiers is a simple probabilistic classification model based on Bayes Theorem. It is a simple, yet powerful classification model. Since Naive Bayes classifiers simply classifies sets of data by which class has the highest likelihood, Naive Bayes classifiers can use any dsitribution or model that outputs a probability.\n+\n+An IPython notebook example demonstrating a Naive Bayes classifier using multivariate distributions can be [found here](https://github.com/jmschrei/pomegranate/blob/master/examples/naivebayes_multivariate_male_female.ipynb).\n+\n+Naive Bayes implements the following methods:\n+\n+```\n+predict_log_proba( X ) : Input a set of data and output the log probability of each sample under each distribution\n+predict_proba( X ) : Input a set of data and output the probability of each sample under each distribution\n+predict( X ) : Input a set of data and classify each sample under one of the distributions\n+fit( X, y ) : Fit the Naive Bayes classifier to a set of training data, with X being the sample, and y being the correct classification for each sample\n+```\n+\n+## Initialization\n+\n+Naive Bayes can be initialized a number of ways. The classifier can be initialized by either passing in the initial distribution objects or by passing in the constructor and the number of components.\n+\n+For example, here is an initialization using an already initialized normal distribution for class 0, a uniform distribution for class 1, and an exponential distribution for class 2 .\n+\n+```Python\n+clf = NaiveBayes([ NormalDistribution( 5, 2 ), UniformDistribution( 0, 10 ), ExponentialDistribution( 1.0 ) ])\n+```\n+\n+Since Naive Bayes classifiers simply compares the likelihood of a sample occurring under different models, it can be initialized with any model in pomegranate. This is assuming that all the models take the same type of input.\n+\n+```Python\n+multi = MultivariateGaussianDistribution( means=[ 5, 5 ], covariance=[[ 2, 0 ], [ 0, 2 ]] )\n+indie = IndependentComponentsDistribution( distributions=[ UniformDistribution(0, 10), UniformDistribution(0, 10) ])\n+clf = NaiveBayes([ mutli, indie ])\n+```\n+\n+Naive Bayes classifiers can also take Hidden Markov Models as input as well as Bayesian Networks.\n+\n+If all the models in the Naive Bayes classifier use the same type of model, then Naive Bayes can be initialized by passing in the constructor for the model and the number of classses there are.\n+\n+```Python\n+clf = NaiveBayes( NormalDistribution, n_components=5 )\n+```\n+\n+**Warning!** keep in mind that if Naive Bayes is initialized this way then all the classes must be fitted to some data before any prediction methods are called.\n+\n+Finally, Naive Bayes must be given at least a model or n_components must be specified otherwise a ValueError will be thrown.\n+\n+## Prediction\n+\n+Naive Bayes has three different prediction methods which all take the same input, an numpy array of samples. These methods are predict_proba, predict_log_proba, and predict which output, respectively, the probability of each sample occurring under each model, the log probability of each sample occurring under each model, and the model each sample is classified as.\n+\n+Since Naive Bayes uses Bayes Theorem, the probability of a sample occurring under each model is in respect to the total sample space of the sample occurring under all the models.\n+\n+Given our Naive Bayes classifier from above consisting of three univariate distribution, calling predict_proba on five samples would look like the following.\n+\n+```Python\n+probs = clf.predict_proba( np.array([ 0, 1, 2, 3, 4 ]) )\n+```\n+With the output being the following numpy array.\n+\n+```Python\n+[[ 0.00790443  0.09019051  0.90190506]\n+ [ 0.05455011  0.20207126  0.74337863]\n+ [ 0.21579499  0.33322883  0.45097618]\n+ [ 0.44681566  0.36931382  0.18387052]\n+ [ 0.59804205  0.33973357  0.06222437]]\n+```\n+\n+With models that take in multiple inputs, the input to predict_proba would take the inputs as a list of lists. This would look like the following.\n+\n+```Python\n+probs = clf.predict_proba( np.array([[ 0, 4 ],\n+\t\t\t\t\t\t\t\t\t [ 1, 3 ],\n+\t\t\t\t\t\t\t\t\t [ 2, 2 ],\n+\t\t\t\t\t\t\t\t\t [ 3, 1 ],\n+\t\t\t\t\t\t\t\t\t [ 4, 0 ]]) )\n+```\n+\n+With the output having the same format as the example above. Keep in mind that the samples taken as input must be the same length as one another unless Naive Bayes is being used to compare Hidden Markov Models.\n+\n+The method predict_log_proba is called in the exact same manner, and its output is formatted exactly the same as predict_proba. The only difference is the output values are the log probabilities rather than the probabitilies of each sample occurring.\n+\n+```Python\n+log_probs = clf.predict_log_proba( np.array([ 0, 1, 2, 3, 4 ]) )\n+```\n+\n+Finally, there is the method predict. Again, this takes the same formatted input as predict_proba and predict_log_proba. However instead of outputting a array of arrays, predict outputs an array of classifications for each sample. Here is a call using the Naive Bayes made up of three univariate distributions once again.\n+\n+```Python\n+predictions = clf.predict( np.array([ 0, 1, 2, 3, 4 ]) )\n+```\n+\n+The corresponding output would be.\n+\n+```Python\n+[ 2, 2, 2, 0, 0 ]\n+```\n+\n+## Fitting","path":"docs/naivebayes.md","position":98,"original_position":98,"commit_id":"b67c405bc2f458034e563a3fdf6cdb0ae1d73ea5","original_commit_id":"b67c405bc2f458034e563a3fdf6cdb0ae1d73ea5","user":{"login":"jmschrei","id":3916816,"avatar_url":"https://avatars.githubusercontent.com/u/3916816?v=3","gravatar_id":"","url":"https://api.github.com/users/jmschrei","html_url":"https://github.com/jmschrei","followers_url":"https://api.github.com/users/jmschrei/followers","following_url":"https://api.github.com/users/jmschrei/following{/other_user}","gists_url":"https://api.github.com/users/jmschrei/gists{/gist_id}","starred_url":"https://api.github.com/users/jmschrei/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jmschrei/subscriptions","organizations_url":"https://api.github.com/users/jmschrei/orgs","repos_url":"https://api.github.com/users/jmschrei/repos","events_url":"https://api.github.com/users/jmschrei/events{/privacy}","received_events_url":"https://api.github.com/users/jmschrei/received_events","type":"User","site_admin":false},"body":"Put fitting before prediction","created_at":"2016-02-16T19:57:03Z","updated_at":"2016-02-16T19:57:03Z","html_url":"https://github.com/jmschrei/pomegranate/pull/80#discussion_r53068675","pull_request_url":"https://api.github.com/repos/jmschrei/pomegranate/pulls/80","_links":{"self":{"href":"https://api.github.com/repos/jmschrei/pomegranate/pulls/comments/53068675"},"html":{"href":"https://github.com/jmschrei/pomegranate/pull/80#discussion_r53068675"},"pull_request":{"href":"https://api.github.com/repos/jmschrei/pomegranate/pulls/80"}}},"pull_request":{"url":"https://api.github.com/repos/jmschrei/pomegranate/pulls/80","id":59542572,"html_url":"https://github.com/jmschrei/pomegranate/pull/80","diff_url":"https://github.com/jmschrei/pomegranate/pull/80.diff","patch_url":"https://github.com/jmschrei/pomegranate/pull/80.patch","issue_url":"https://api.github.com/repos/jmschrei/pomegranate/issues/80","number":80,"state":"open","locked":false,"title":"ENH Naive Bayes Documentation","user":{"login":"neonrights","id":2925802,"avatar_url":"https://avatars.githubusercontent.com/u/2925802?v=3","gravatar_id":"","url":"https://api.github.com/users/neonrights","html_url":"https://github.com/neonrights","followers_url":"https://api.github.com/users/neonrights/followers","following_url":"https://api.github.com/users/neonrights/following{/other_user}","gists_url":"https://api.github.com/users/neonrights/gists{/gist_id}","starred_url":"https://api.github.com/users/neonrights/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/neonrights/subscriptions","organizations_url":"https://api.github.com/users/neonrights/orgs","repos_url":"https://api.github.com/users/neonrights/repos","events_url":"https://api.github.com/users/neonrights/events{/privacy}","received_events_url":"https://api.github.com/users/neonrights/received_events","type":"User","site_admin":false},"body":"Created documentation showing how to use methods for naive bayes for read the docs.","created_at":"2016-02-16T19:39:46Z","updated_at":"2016-02-16T19:57:03Z","closed_at":null,"merged_at":null,"merge_commit_sha":"30e1b287eb08d540cebf092ca4a2910b12bb9d91","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/jmschrei/pomegranate/pulls/80/commits","review_comments_url":"https://api.github.com/repos/jmschrei/pomegranate/pulls/80/comments","review_comment_url":"https://api.github.com/repos/jmschrei/pomegranate/pulls/comments{/number}","comments_url":"https://api.github.com/repos/jmschrei/pomegranate/issues/80/comments","statuses_url":"https://api.github.com/repos/jmschrei/pomegranate/statuses/b67c405bc2f458034e563a3fdf6cdb0ae1d73ea5","head":{"label":"neonrights:naivebayes-docs","ref":"naivebayes-docs","sha":"b67c405bc2f458034e563a3fdf6cdb0ae1d73ea5","user":{"login":"neonrights","id":2925802,"avatar_url":"https://avatars.githubusercontent.com/u/2925802?v=3","gravatar_id":"","url":"https://api.github.com/users/neonrights","html_url":"https://github.com/neonrights","followers_url":"https://api.github.com/users/neonrights/followers","following_url":"https://api.github.com/users/neonrights/following{/other_user}","gists_url":"https://api.github.com/users/neonrights/gists{/gist_id}","starred_url":"https://api.github.com/users/neonrights/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/neonrights/subscriptions","organizations_url":"https://api.github.com/users/neonrights/orgs","repos_url":"https://api.github.com/users/neonrights/repos","events_url":"https://api.github.com/users/neonrights/events{/privacy}","received_events_url":"https://api.github.com/users/neonrights/received_events","type":"User","site_admin":false},"repo":{"id":49087669,"name":"pomegranate","full_name":"neonrights/pomegranate","owner":{"login":"neonrights","id":2925802,"avatar_url":"https://avatars.githubusercontent.com/u/2925802?v=3","gravatar_id":"","url":"https://api.github.com/users/neonrights","html_url":"https://github.com/neonrights","followers_url":"https://api.github.com/users/neonrights/followers","following_url":"https://api.github.com/users/neonrights/following{/other_user}","gists_url":"https://api.github.com/users/neonrights/gists{/gist_id}","starred_url":"https://api.github.com/users/neonrights/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/neonrights/subscriptions","organizations_url":"https://api.github.com/users/neonrights/orgs","repos_url":"https://api.github.com/users/neonrights/repos","events_url":"https://api.github.com/users/neonrights/events{/privacy}","received_events_url":"https://api.github.com/users/neonrights/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/neonrights/pomegranate","description":"Graphical models for Python, implemented in Cython for speed.","fork":true,"url":"https://api.github.com/repos/neonrights/pomegranate","forks_url":"https://api.github.com/repos/neonrights/pomegranate/forks","keys_url":"https://api.github.com/repos/neonrights/pomegranate/keys{/key_id}","collaborators_url":"https://api.github.com/repos/neonrights/pomegranate/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/neonrights/pomegranate/teams","hooks_url":"https://api.github.com/repos/neonrights/pomegranate/hooks","issue_events_url":"https://api.github.com/repos/neonrights/pomegranate/issues/events{/number}","events_url":"https://api.github.com/repos/neonrights/pomegranate/events","assignees_url":"https://api.github.com/repos/neonrights/pomegranate/assignees{/user}","branches_url":"https://api.github.com/repos/neonrights/pomegranate/branches{/branch}","tags_url":"https://api.github.com/repos/neonrights/pomegranate/tags","blobs_url":"https://api.github.com/repos/neonrights/pomegranate/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/neonrights/pomegranate/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/neonrights/pomegranate/git/refs{/sha}","trees_url":"https://api.github.com/repos/neonrights/pomegranate/git/trees{/sha}","statuses_url":"https://api.github.com/repos/neonrights/pomegranate/statuses/{sha}","languages_url":"https://api.github.com/repos/neonrights/pomegranate/languages","stargazers_url":"https://api.github.com/repos/neonrights/pomegranate/stargazers","contributors_url":"https://api.github.com/repos/neonrights/pomegranate/contributors","subscribers_url":"https://api.github.com/repos/neonrights/pomegranate/subscribers","subscription_url":"https://api.github.com/repos/neonrights/pomegranate/subscription","commits_url":"https://api.github.com/repos/neonrights/pomegranate/commits{/sha}","git_commits_url":"https://api.github.com/repos/neonrights/pomegranate/git/commits{/sha}","comments_url":"https://api.github.com/repos/neonrights/pomegranate/comments{/number}","issue_comment_url":"https://api.github.com/repos/neonrights/pomegranate/issues/comments{/number}","contents_url":"https://api.github.com/repos/neonrights/pomegranate/contents/{+path}","compare_url":"https://api.github.com/repos/neonrights/pomegranate/compare/{base}...{head}","merges_url":"https://api.github.com/repos/neonrights/pomegranate/merges","archive_url":"https://api.github.com/repos/neonrights/pomegranate/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/neonrights/pomegranate/downloads","issues_url":"https://api.github.com/repos/neonrights/pomegranate/issues{/number}","pulls_url":"https://api.github.com/repos/neonrights/pomegranate/pulls{/number}","milestones_url":"https://api.github.com/repos/neonrights/pomegranate/milestones{/number}","notifications_url":"https://api.github.com/repos/neonrights/pomegranate/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/neonrights/pomegranate/labels{/name}","releases_url":"https://api.github.com/repos/neonrights/pomegranate/releases{/id}","deployments_url":"https://api.github.com/repos/neonrights/pomegranate/deployments","created_at":"2016-01-05T19:25:59Z","updated_at":"2016-01-19T01:16:39Z","pushed_at":"2016-02-16T19:50:11Z","git_url":"git://github.com/neonrights/pomegranate.git","ssh_url":"git@github.com:neonrights/pomegranate.git","clone_url":"https://github.com/neonrights/pomegranate.git","svn_url":"https://github.com/neonrights/pomegranate","homepage":null,"size":11335,"stargazers_count":0,"watchers_count":0,"language":"Python","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":"jmschrei:master","ref":"master","sha":"45082ecf0ef31d44327ee9fcdce3fb83de0bd80c","user":{"login":"jmschrei","id":3916816,"avatar_url":"https://avatars.githubusercontent.com/u/3916816?v=3","gravatar_id":"","url":"https://api.github.com/users/jmschrei","html_url":"https://github.com/jmschrei","followers_url":"https://api.github.com/users/jmschrei/followers","following_url":"https://api.github.com/users/jmschrei/following{/other_user}","gists_url":"https://api.github.com/users/jmschrei/gists{/gist_id}","starred_url":"https://api.github.com/users/jmschrei/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jmschrei/subscriptions","organizations_url":"https://api.github.com/users/jmschrei/orgs","repos_url":"https://api.github.com/users/jmschrei/repos","events_url":"https://api.github.com/users/jmschrei/events{/privacy}","received_events_url":"https://api.github.com/users/jmschrei/received_events","type":"User","site_admin":false},"repo":{"id":27089158,"name":"pomegranate","full_name":"jmschrei/pomegranate","owner":{"login":"jmschrei","id":3916816,"avatar_url":"https://avatars.githubusercontent.com/u/3916816?v=3","gravatar_id":"","url":"https://api.github.com/users/jmschrei","html_url":"https://github.com/jmschrei","followers_url":"https://api.github.com/users/jmschrei/followers","following_url":"https://api.github.com/users/jmschrei/following{/other_user}","gists_url":"https://api.github.com/users/jmschrei/gists{/gist_id}","starred_url":"https://api.github.com/users/jmschrei/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jmschrei/subscriptions","organizations_url":"https://api.github.com/users/jmschrei/orgs","repos_url":"https://api.github.com/users/jmschrei/repos","events_url":"https://api.github.com/users/jmschrei/events{/privacy}","received_events_url":"https://api.github.com/users/jmschrei/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jmschrei/pomegranate","description":"Graphical models for Python, implemented in Cython for speed.","fork":false,"url":"https://api.github.com/repos/jmschrei/pomegranate","forks_url":"https://api.github.com/repos/jmschrei/pomegranate/forks","keys_url":"https://api.github.com/repos/jmschrei/pomegranate/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jmschrei/pomegranate/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jmschrei/pomegranate/teams","hooks_url":"https://api.github.com/repos/jmschrei/pomegranate/hooks","issue_events_url":"https://api.github.com/repos/jmschrei/pomegranate/issues/events{/number}","events_url":"https://api.github.com/repos/jmschrei/pomegranate/events","assignees_url":"https://api.github.com/repos/jmschrei/pomegranate/assignees{/user}","branches_url":"https://api.github.com/repos/jmschrei/pomegranate/branches{/branch}","tags_url":"https://api.github.com/repos/jmschrei/pomegranate/tags","blobs_url":"https://api.github.com/repos/jmschrei/pomegranate/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jmschrei/pomegranate/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jmschrei/pomegranate/git/refs{/sha}","trees_url":"https://api.github.com/repos/jmschrei/pomegranate/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jmschrei/pomegranate/statuses/{sha}","languages_url":"https://api.github.com/repos/jmschrei/pomegranate/languages","stargazers_url":"https://api.github.com/repos/jmschrei/pomegranate/stargazers","contributors_url":"https://api.github.com/repos/jmschrei/pomegranate/contributors","subscribers_url":"https://api.github.com/repos/jmschrei/pomegranate/subscribers","subscription_url":"https://api.github.com/repos/jmschrei/pomegranate/subscription","commits_url":"https://api.github.com/repos/jmschrei/pomegranate/commits{/sha}","git_commits_url":"https://api.github.com/repos/jmschrei/pomegranate/git/commits{/sha}","comments_url":"https://api.github.com/repos/jmschrei/pomegranate/comments{/number}","issue_comment_url":"https://api.github.com/repos/jmschrei/pomegranate/issues/comments{/number}","contents_url":"https://api.github.com/repos/jmschrei/pomegranate/contents/{+path}","compare_url":"https://api.github.com/repos/jmschrei/pomegranate/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jmschrei/pomegranate/merges","archive_url":"https://api.github.com/repos/jmschrei/pomegranate/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jmschrei/pomegranate/downloads","issues_url":"https://api.github.com/repos/jmschrei/pomegranate/issues{/number}","pulls_url":"https://api.github.com/repos/jmschrei/pomegranate/pulls{/number}","milestones_url":"https://api.github.com/repos/jmschrei/pomegranate/milestones{/number}","notifications_url":"https://api.github.com/repos/jmschrei/pomegranate/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jmschrei/pomegranate/labels{/name}","releases_url":"https://api.github.com/repos/jmschrei/pomegranate/releases{/id}","deployments_url":"https://api.github.com/repos/jmschrei/pomegranate/deployments","created_at":"2014-11-24T18:36:58Z","updated_at":"2016-02-16T00:50:07Z","pushed_at":"2016-02-16T19:52:20Z","git_url":"git://github.com/jmschrei/pomegranate.git","ssh_url":"git@github.com:jmschrei/pomegranate.git","clone_url":"https://github.com/jmschrei/pomegranate.git","svn_url":"https://github.com/jmschrei/pomegranate","homepage":null,"size":11400,"stargazers_count":376,"watchers_count":376,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":38,"mirror_url":null,"open_issues_count":15,"forks":38,"open_issues":15,"watchers":376,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/jmschrei/pomegranate/pulls/80"},"html":{"href":"https://github.com/jmschrei/pomegranate/pull/80"},"issue":{"href":"https://api.github.com/repos/jmschrei/pomegranate/issues/80"},"comments":{"href":"https://api.github.com/repos/jmschrei/pomegranate/issues/80/comments"},"review_comments":{"href":"https://api.github.com/repos/jmschrei/pomegranate/pulls/80/comments"},"review_comment":{"href":"https://api.github.com/repos/jmschrei/pomegranate/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/jmschrei/pomegranate/pulls/80/commits"},"statuses":{"href":"https://api.github.com/repos/jmschrei/pomegranate/statuses/b67c405bc2f458034e563a3fdf6cdb0ae1d73ea5"}}}}