{"action":"created","issue":{"url":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/7680","repository_url":"https://api.github.com/repos/scikit-learn/scikit-learn","labels_url":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/7680/labels{/name}","comments_url":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/7680/comments","events_url":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/7680/events","html_url":"https://github.com/scikit-learn/scikit-learn/pull/7680","id":183282825,"number":7680,"title":"[MRG] Fix #6420 Cloning decision tree estimators breaks criterion objects","user":{"login":"olologin","id":4762581,"avatar_url":"https://avatars.githubusercontent.com/u/4762581?v=3","gravatar_id":"","url":"https://api.github.com/users/olologin","html_url":"https://github.com/olologin","followers_url":"https://api.github.com/users/olologin/followers","following_url":"https://api.github.com/users/olologin/following{/other_user}","gists_url":"https://api.github.com/users/olologin/gists{/gist_id}","starred_url":"https://api.github.com/users/olologin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/olologin/subscriptions","organizations_url":"https://api.github.com/users/olologin/orgs","repos_url":"https://api.github.com/users/olologin/repos","events_url":"https://api.github.com/users/olologin/events{/privacy}","received_events_url":"https://api.github.com/users/olologin/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/scikit-learn/scikit-learn/milestones/22","html_url":"https://github.com/scikit-learn/scikit-learn/milestones/0.18.1","labels_url":"https://api.github.com/repos/scikit-learn/scikit-learn/milestones/22/labels","id":2046567,"number":22,"title":"0.18.1","description":"Urgent fixes to bugs and web site issues.","creator":{"login":"jnothman","id":78827,"avatar_url":"https://avatars.githubusercontent.com/u/78827?v=3","gravatar_id":"","url":"https://api.github.com/users/jnothman","html_url":"https://github.com/jnothman","followers_url":"https://api.github.com/users/jnothman/followers","following_url":"https://api.github.com/users/jnothman/following{/other_user}","gists_url":"https://api.github.com/users/jnothman/gists{/gist_id}","starred_url":"https://api.github.com/users/jnothman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jnothman/subscriptions","organizations_url":"https://api.github.com/users/jnothman/orgs","repos_url":"https://api.github.com/users/jnothman/repos","events_url":"https://api.github.com/users/jnothman/events{/privacy}","received_events_url":"https://api.github.com/users/jnothman/received_events","type":"User","site_admin":false},"open_issues":23,"closed_issues":17,"state":"open","created_at":"2016-10-04T11:55:58Z","updated_at":"2016-10-18T11:25:31Z","due_on":null,"closed_at":null},"comments":7,"created_at":"2016-10-16T18:37:39Z","updated_at":"2016-10-19T04:54:08Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/7680","html_url":"https://github.com/scikit-learn/scikit-learn/pull/7680","diff_url":"https://github.com/scikit-learn/scikit-learn/pull/7680.diff","patch_url":"https://github.com/scikit-learn/scikit-learn/pull/7680.patch"},"body":"#### Reference Issue\r\nFixes #6420 \r\n\r\n#### What does this implement/fix? Explain your changes.\r\nThis fix changes `__reduce__` methods of criterion objects which are used for pickling/cloning.\r\n\r\nThere was memory management problem, function `sizet_ptr_to_ndarray` from `tree/_utils.pyx` returned np.array object, but this np.array object didn't own underlying memory. In some cases we call `__repr__` on criterion object, this `__repr__` returns needed info for pickling/cloning, this info includes n_classes array (for `ClassificationCriterion`), and Criterion object gets removed. If we read info returned by `__repr__` after this - n_classes will be filled with garbage.\r\n\r\n\tfrom sklearn.tree import tree\r\n\timport copy\r\n\timport numpy as np\r\n\r\n\tgini = tree._criterion.ClassificationCriterion(n_outputs=1, n_classes=np.array([2]))\r\n\tgini.__reduce__()\r\n\tcopy.deepcopy(gini).__reduce__()\r\n        Out[1] (sklearn.tree._criterion.ClassificationCriterion, (1, array([4314681712])), {})\r\n\r\nAlso I added `__repr__` functions for classes which didn't have them, because otherwise class of object after unpickling/cloning changes to more common. For example after cloning `Gini` criterion we will get `ClassificationCriterion`.\r\n\r\n\r\n\tfrom sklearn.tree import tree\r\n\timport copy\r\n\timport numpy as np\r\n\r\n\tgini = tree._criterion.Gini(n_outputs=1, n_classes=np.array([2]))\r\n\tgini_copy = copy.deepcopy(gini)\r\n\tgini_copy.__class__\r\n        Out[1]: sklearn.tree._criterion.ClassificationCriterion\r\n\r\n\r\n#### Any other comments?\r\nMake suggestions\r\n"},"comment":{"url":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/comments/254710156","html_url":"https://github.com/scikit-learn/scikit-learn/pull/7680#issuecomment-254710156","issue_url":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/7680","id":254710156,"user":{"login":"jnothman","id":78827,"avatar_url":"https://avatars.githubusercontent.com/u/78827?v=3","gravatar_id":"","url":"https://api.github.com/users/jnothman","html_url":"https://github.com/jnothman","followers_url":"https://api.github.com/users/jnothman/followers","following_url":"https://api.github.com/users/jnothman/following{/other_user}","gists_url":"https://api.github.com/users/jnothman/gists{/gist_id}","starred_url":"https://api.github.com/users/jnothman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jnothman/subscriptions","organizations_url":"https://api.github.com/users/jnothman/orgs","repos_url":"https://api.github.com/users/jnothman/repos","events_url":"https://api.github.com/users/jnothman/events{/privacy}","received_events_url":"https://api.github.com/users/jnothman/received_events","type":"User","site_admin":false},"created_at":"2016-10-19T04:54:08Z","updated_at":"2016-10-19T04:54:08Z","body":"LGTM, thanks!"}}
{"actor":{"display_login":"jnothman"}}