{"action":"created","comment":{"url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/comments/241201270","pull_request_review_id":184415816,"id":241201270,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDI0MTIwMTI3MA==","diff_hunk":"@@ -951,3 +988,241 @@ def _joint_log_likelihood(self, X):\n         jll += self.class_log_prior_ + neg_prob.sum(axis=1)\n \n         return jll\n+\n+\n+class CategoricalNB(BaseDiscreteNB):\n+    \"\"\"Naive Bayes classifier for categorical features\n+\n+    The categorical Naive Bayes classifier is suitable for classification with\n+    discrete features, that are categorically distributed. The categories of\n+    each feature are drawn from a categorical distribution.\n+\n+    Read more in the :ref:`User Guide <categorical_naive_bayes>`.\n+\n+    Parameters\n+    ----------\n+    alpha : float, optional (default=1.0)\n+        Additive (Laplace/Lidstone) smoothing parameter\n+        (0 for no smoothing).\n+\n+    fit_prior : boolean, optional (default=True)\n+        Whether to learn class prior probabilities or not.\n+        If false, a uniform prior will be used.\n+\n+    class_prior : array-like, size (n_classes,), optional (default=None)\n+        Prior probabilities of the classes. If specified the priors are not\n+        adjusted according to the data.\n+\n+    on_unseen_cats : String\n+        Can be 'ignore', 'warn' or 'error'. Determines the behaviour of the\n+        classifier, if it encounters unseen categories in the prediction step.\n+\n+    Attributes\n+    ----------\n+    class_log_prior_ : array, shape (n_classes, )\n+        Smoothed empirical log probability for each class.\n+\n+    feature_log_prob_ : array, shape (n_classes, n_features)\n+        Empirical log probability of features\n+        given a class, ``P(x_i|y)``.\n+\n+    class_count_ : array, shape (n_classes,)\n+        Number of samples encountered for each class during fitting. This\n+        value is weighted by the sample weight when provided.\n+\n+    category_count_ : dict of arrays, len n_features\n+        Holds arrays of shape (n_classes, n_categories of respective feature)\n+        for each feature. Each array provides the number of samples\n+        encountered for each class and category of the specific feature.\n+\n+    n_features_ : int\n+        Number of features of each sample.\n+\n+    Examples\n+    --------\n+    >>> import numpy as np\n+    >>> X = np.random.randint(5, size=(6, 100))\n+    >>> y = np.array([1, 2, 3, 4, 5, 6])\n+    >>> from sklearn.naive_bayes import CategoricalNB\n+    >>> clf = CategoricalNB()\n+    >>> clf.fit(X, y)\n+    CategoricalNB(alpha=1.0, class_prior=None, fit_prior=True)\n+    >>> print(clf.predict(X[2:3]))\n+    [3]\n+    \"\"\"\n+\n+    old_numpy_ = parse_version(np.__version__) < parse_version('1.9.0')\n+\n+    def __init__(self, alpha=1.0, fit_prior=True, class_prior=None,\n+                 on_unseen_cats='warn'):\n+        if CategoricalNB.old_numpy_:\n+            warnings.warn(\n+                ('numpy is older than 1.9.0. Therefore assure that X is'\n+                 'castable to int without loss of information and all '\n+                 'features of X are greater or equal 0.'))\n+        self.alpha = alpha\n+        self.fit_prior = fit_prior\n+        self.class_prior = class_prior\n+        # ignore warn or raise\n+        self.on_unseen_cats = on_unseen_cats","path":"sklearn/naive_bayes.py","position":344,"original_position":344,"commit_id":"4c6d8ba7c5862b33edf2b2c9f829cf3a9555041b","original_commit_id":"4c6d8ba7c5862b33edf2b2c9f829cf3a9555041b","user":{"login":"FlorianWilhelm","id":3184072,"node_id":"MDQ6VXNlcjMxODQwNzI=","avatar_url":"https://avatars2.githubusercontent.com/u/3184072?v=4","gravatar_id":"","url":"https://api.github.com/users/FlorianWilhelm","html_url":"https://github.com/FlorianWilhelm","followers_url":"https://api.github.com/users/FlorianWilhelm/followers","following_url":"https://api.github.com/users/FlorianWilhelm/following{/other_user}","gists_url":"https://api.github.com/users/FlorianWilhelm/gists{/gist_id}","starred_url":"https://api.github.com/users/FlorianWilhelm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/FlorianWilhelm/subscriptions","organizations_url":"https://api.github.com/users/FlorianWilhelm/orgs","repos_url":"https://api.github.com/users/FlorianWilhelm/repos","events_url":"https://api.github.com/users/FlorianWilhelm/events{/privacy}","received_events_url":"https://api.github.com/users/FlorianWilhelm/received_events","type":"User","site_admin":false},"body":"One could add a check here `if on_unseen_cats not in ('ignore', 'warn', 'raise')` and fail accordingly.","created_at":"2018-12-12T22:00:15Z","updated_at":"2018-12-12T22:00:16Z","html_url":"https://github.com/scikit-learn/scikit-learn/pull/12569#discussion_r241201270","pull_request_url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/12569","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/comments/241201270"},"html":{"href":"https://github.com/scikit-learn/scikit-learn/pull/12569#discussion_r241201270"},"pull_request":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/12569"}}},"pull_request":{"url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/12569","id":230137315,"node_id":"MDExOlB1bGxSZXF1ZXN0MjMwMTM3MzE1","html_url":"https://github.com/scikit-learn/scikit-learn/pull/12569","diff_url":"https://github.com/scikit-learn/scikit-learn/pull/12569.diff","patch_url":"https://github.com/scikit-learn/scikit-learn/pull/12569.patch","issue_url":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/12569","number":12569,"state":"open","locked":false,"title":"[WIP] Add Categorical Naive Bayes","user":{"login":"timbicker","id":28577763,"node_id":"MDQ6VXNlcjI4NTc3NzYz","avatar_url":"https://avatars1.githubusercontent.com/u/28577763?v=4","gravatar_id":"","url":"https://api.github.com/users/timbicker","html_url":"https://github.com/timbicker","followers_url":"https://api.github.com/users/timbicker/followers","following_url":"https://api.github.com/users/timbicker/following{/other_user}","gists_url":"https://api.github.com/users/timbicker/gists{/gist_id}","starred_url":"https://api.github.com/users/timbicker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/timbicker/subscriptions","organizations_url":"https://api.github.com/users/timbicker/orgs","repos_url":"https://api.github.com/users/timbicker/repos","events_url":"https://api.github.com/users/timbicker/events{/privacy}","received_events_url":"https://api.github.com/users/timbicker/received_events","type":"User","site_admin":false},"body":"#### Reference Issues/PRs\r\nImpelements Categorical NB from [#10856](https://github.com/scikit-learn/scikit-learn/issues/10856)\r\n\r\n#### What does this implement/fix? Explain your changes.\r\nThis implementation adds the NB classifier for categorical features.\r\n\r\n#### Any other comments?\r\n- [x] implement categorical NB functionality\r\n- [x] check and write doc strings\r\n- [ ] add full test coverage\r\n- [ ] write a documentation\r\n- [ ] provide an example\r\n","created_at":"2018-11-12T13:38:46Z","updated_at":"2018-12-12T22:00:16Z","closed_at":null,"merged_at":null,"merge_commit_sha":"eb8e918ed95350e38dce66a19802623bda02d2e2","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/12569/commits","review_comments_url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/12569/comments","review_comment_url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/comments{/number}","comments_url":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/12569/comments","statuses_url":"https://api.github.com/repos/scikit-learn/scikit-learn/statuses/4c6d8ba7c5862b33edf2b2c9f829cf3a9555041b","head":{"label":"timbicker:categorical_NB","ref":"categorical_NB","sha":"4c6d8ba7c5862b33edf2b2c9f829cf3a9555041b","user":{"login":"timbicker","id":28577763,"node_id":"MDQ6VXNlcjI4NTc3NzYz","avatar_url":"https://avatars1.githubusercontent.com/u/28577763?v=4","gravatar_id":"","url":"https://api.github.com/users/timbicker","html_url":"https://github.com/timbicker","followers_url":"https://api.github.com/users/timbicker/followers","following_url":"https://api.github.com/users/timbicker/following{/other_user}","gists_url":"https://api.github.com/users/timbicker/gists{/gist_id}","starred_url":"https://api.github.com/users/timbicker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/timbicker/subscriptions","organizations_url":"https://api.github.com/users/timbicker/orgs","repos_url":"https://api.github.com/users/timbicker/repos","events_url":"https://api.github.com/users/timbicker/events{/privacy}","received_events_url":"https://api.github.com/users/timbicker/received_events","type":"User","site_admin":false},"repo":{"id":146195190,"node_id":"MDEwOlJlcG9zaXRvcnkxNDYxOTUxOTA=","name":"scikit-learn","full_name":"timbicker/scikit-learn","private":false,"owner":{"login":"timbicker","id":28577763,"node_id":"MDQ6VXNlcjI4NTc3NzYz","avatar_url":"https://avatars1.githubusercontent.com/u/28577763?v=4","gravatar_id":"","url":"https://api.github.com/users/timbicker","html_url":"https://github.com/timbicker","followers_url":"https://api.github.com/users/timbicker/followers","following_url":"https://api.github.com/users/timbicker/following{/other_user}","gists_url":"https://api.github.com/users/timbicker/gists{/gist_id}","starred_url":"https://api.github.com/users/timbicker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/timbicker/subscriptions","organizations_url":"https://api.github.com/users/timbicker/orgs","repos_url":"https://api.github.com/users/timbicker/repos","events_url":"https://api.github.com/users/timbicker/events{/privacy}","received_events_url":"https://api.github.com/users/timbicker/received_events","type":"User","site_admin":false},"html_url":"https://github.com/timbicker/scikit-learn","description":"scikit-learn: machine learning in Python","fork":true,"url":"https://api.github.com/repos/timbicker/scikit-learn","forks_url":"https://api.github.com/repos/timbicker/scikit-learn/forks","keys_url":"https://api.github.com/repos/timbicker/scikit-learn/keys{/key_id}","collaborators_url":"https://api.github.com/repos/timbicker/scikit-learn/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/timbicker/scikit-learn/teams","hooks_url":"https://api.github.com/repos/timbicker/scikit-learn/hooks","issue_events_url":"https://api.github.com/repos/timbicker/scikit-learn/issues/events{/number}","events_url":"https://api.github.com/repos/timbicker/scikit-learn/events","assignees_url":"https://api.github.com/repos/timbicker/scikit-learn/assignees{/user}","branches_url":"https://api.github.com/repos/timbicker/scikit-learn/branches{/branch}","tags_url":"https://api.github.com/repos/timbicker/scikit-learn/tags","blobs_url":"https://api.github.com/repos/timbicker/scikit-learn/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/timbicker/scikit-learn/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/timbicker/scikit-learn/git/refs{/sha}","trees_url":"https://api.github.com/repos/timbicker/scikit-learn/git/trees{/sha}","statuses_url":"https://api.github.com/repos/timbicker/scikit-learn/statuses/{sha}","languages_url":"https://api.github.com/repos/timbicker/scikit-learn/languages","stargazers_url":"https://api.github.com/repos/timbicker/scikit-learn/stargazers","contributors_url":"https://api.github.com/repos/timbicker/scikit-learn/contributors","subscribers_url":"https://api.github.com/repos/timbicker/scikit-learn/subscribers","subscription_url":"https://api.github.com/repos/timbicker/scikit-learn/subscription","commits_url":"https://api.github.com/repos/timbicker/scikit-learn/commits{/sha}","git_commits_url":"https://api.github.com/repos/timbicker/scikit-learn/git/commits{/sha}","comments_url":"https://api.github.com/repos/timbicker/scikit-learn/comments{/number}","issue_comment_url":"https://api.github.com/repos/timbicker/scikit-learn/issues/comments{/number}","contents_url":"https://api.github.com/repos/timbicker/scikit-learn/contents/{+path}","compare_url":"https://api.github.com/repos/timbicker/scikit-learn/compare/{base}...{head}","merges_url":"https://api.github.com/repos/timbicker/scikit-learn/merges","archive_url":"https://api.github.com/repos/timbicker/scikit-learn/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/timbicker/scikit-learn/downloads","issues_url":"https://api.github.com/repos/timbicker/scikit-learn/issues{/number}","pulls_url":"https://api.github.com/repos/timbicker/scikit-learn/pulls{/number}","milestones_url":"https://api.github.com/repos/timbicker/scikit-learn/milestones{/number}","notifications_url":"https://api.github.com/repos/timbicker/scikit-learn/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/timbicker/scikit-learn/labels{/name}","releases_url":"https://api.github.com/repos/timbicker/scikit-learn/releases{/id}","deployments_url":"https://api.github.com/repos/timbicker/scikit-learn/deployments","created_at":"2018-08-26T16:02:22Z","updated_at":"2018-11-05T10:14:42Z","pushed_at":"2018-12-12T17:32:27Z","git_url":"git://github.com/timbicker/scikit-learn.git","ssh_url":"git@github.com:timbicker/scikit-learn.git","clone_url":"https://github.com/timbicker/scikit-learn.git","svn_url":"https://github.com/timbicker/scikit-learn","homepage":"http://scikit-learn.org","size":94364,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"other","name":"Other","spdx_id":"NOASSERTION","url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"scikit-learn:master","ref":"master","sha":"4e8194909ce0f8879ebe8073ae5d37e3fdc8a00f","user":{"login":"scikit-learn","id":365630,"node_id":"MDEyOk9yZ2FuaXphdGlvbjM2NTYzMA==","avatar_url":"https://avatars2.githubusercontent.com/u/365630?v=4","gravatar_id":"","url":"https://api.github.com/users/scikit-learn","html_url":"https://github.com/scikit-learn","followers_url":"https://api.github.com/users/scikit-learn/followers","following_url":"https://api.github.com/users/scikit-learn/following{/other_user}","gists_url":"https://api.github.com/users/scikit-learn/gists{/gist_id}","starred_url":"https://api.github.com/users/scikit-learn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scikit-learn/subscriptions","organizations_url":"https://api.github.com/users/scikit-learn/orgs","repos_url":"https://api.github.com/users/scikit-learn/repos","events_url":"https://api.github.com/users/scikit-learn/events{/privacy}","received_events_url":"https://api.github.com/users/scikit-learn/received_events","type":"Organization","site_admin":false},"repo":{"id":843222,"node_id":"MDEwOlJlcG9zaXRvcnk4NDMyMjI=","name":"scikit-learn","full_name":"scikit-learn/scikit-learn","private":false,"owner":{"login":"scikit-learn","id":365630,"node_id":"MDEyOk9yZ2FuaXphdGlvbjM2NTYzMA==","avatar_url":"https://avatars2.githubusercontent.com/u/365630?v=4","gravatar_id":"","url":"https://api.github.com/users/scikit-learn","html_url":"https://github.com/scikit-learn","followers_url":"https://api.github.com/users/scikit-learn/followers","following_url":"https://api.github.com/users/scikit-learn/following{/other_user}","gists_url":"https://api.github.com/users/scikit-learn/gists{/gist_id}","starred_url":"https://api.github.com/users/scikit-learn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scikit-learn/subscriptions","organizations_url":"https://api.github.com/users/scikit-learn/orgs","repos_url":"https://api.github.com/users/scikit-learn/repos","events_url":"https://api.github.com/users/scikit-learn/events{/privacy}","received_events_url":"https://api.github.com/users/scikit-learn/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/scikit-learn/scikit-learn","description":"scikit-learn: machine learning in Python","fork":false,"url":"https://api.github.com/repos/scikit-learn/scikit-learn","forks_url":"https://api.github.com/repos/scikit-learn/scikit-learn/forks","keys_url":"https://api.github.com/repos/scikit-learn/scikit-learn/keys{/key_id}","collaborators_url":"https://api.github.com/repos/scikit-learn/scikit-learn/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/scikit-learn/scikit-learn/teams","hooks_url":"https://api.github.com/repos/scikit-learn/scikit-learn/hooks","issue_events_url":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/events{/number}","events_url":"https://api.github.com/repos/scikit-learn/scikit-learn/events","assignees_url":"https://api.github.com/repos/scikit-learn/scikit-learn/assignees{/user}","branches_url":"https://api.github.com/repos/scikit-learn/scikit-learn/branches{/branch}","tags_url":"https://api.github.com/repos/scikit-learn/scikit-learn/tags","blobs_url":"https://api.github.com/repos/scikit-learn/scikit-learn/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/scikit-learn/scikit-learn/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/scikit-learn/scikit-learn/git/refs{/sha}","trees_url":"https://api.github.com/repos/scikit-learn/scikit-learn/git/trees{/sha}","statuses_url":"https://api.github.com/repos/scikit-learn/scikit-learn/statuses/{sha}","languages_url":"https://api.github.com/repos/scikit-learn/scikit-learn/languages","stargazers_url":"https://api.github.com/repos/scikit-learn/scikit-learn/stargazers","contributors_url":"https://api.github.com/repos/scikit-learn/scikit-learn/contributors","subscribers_url":"https://api.github.com/repos/scikit-learn/scikit-learn/subscribers","subscription_url":"https://api.github.com/repos/scikit-learn/scikit-learn/subscription","commits_url":"https://api.github.com/repos/scikit-learn/scikit-learn/commits{/sha}","git_commits_url":"https://api.github.com/repos/scikit-learn/scikit-learn/git/commits{/sha}","comments_url":"https://api.github.com/repos/scikit-learn/scikit-learn/comments{/number}","issue_comment_url":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/comments{/number}","contents_url":"https://api.github.com/repos/scikit-learn/scikit-learn/contents/{+path}","compare_url":"https://api.github.com/repos/scikit-learn/scikit-learn/compare/{base}...{head}","merges_url":"https://api.github.com/repos/scikit-learn/scikit-learn/merges","archive_url":"https://api.github.com/repos/scikit-learn/scikit-learn/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/scikit-learn/scikit-learn/downloads","issues_url":"https://api.github.com/repos/scikit-learn/scikit-learn/issues{/number}","pulls_url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls{/number}","milestones_url":"https://api.github.com/repos/scikit-learn/scikit-learn/milestones{/number}","notifications_url":"https://api.github.com/repos/scikit-learn/scikit-learn/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/scikit-learn/scikit-learn/labels{/name}","releases_url":"https://api.github.com/repos/scikit-learn/scikit-learn/releases{/id}","deployments_url":"https://api.github.com/repos/scikit-learn/scikit-learn/deployments","created_at":"2010-08-17T09:43:38Z","updated_at":"2018-12-12T21:41:53Z","pushed_at":"2018-12-12T21:59:26Z","git_url":"git://github.com/scikit-learn/scikit-learn.git","ssh_url":"git@github.com:scikit-learn/scikit-learn.git","clone_url":"https://github.com/scikit-learn/scikit-learn.git","svn_url":"https://github.com/scikit-learn/scikit-learn","homepage":"http://scikit-learn.org","size":97707,"stargazers_count":32246,"watchers_count":32246,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":15893,"mirror_url":null,"archived":false,"open_issues_count":1851,"license":{"key":"other","name":"Other","spdx_id":"NOASSERTION","url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":15893,"open_issues":1851,"watchers":32246,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/12569"},"html":{"href":"https://github.com/scikit-learn/scikit-learn/pull/12569"},"issue":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/12569"},"comments":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/12569/comments"},"review_comments":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/12569/comments"},"review_comment":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/12569/commits"},"statuses":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/statuses/4c6d8ba7c5862b33edf2b2c9f829cf3a9555041b"}},"author_association":"NONE"}}
{"actor":{"display_login":"FlorianWilhelm"}}