{"action":"created","issue":{"url":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/7822","repository_url":"https://api.github.com/repos/scikit-learn/scikit-learn","labels_url":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/7822/labels{/name}","comments_url":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/7822/comments","events_url":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/7822/events","html_url":"https://github.com/scikit-learn/scikit-learn/issues/7822","id":187194229,"number":7822,"title":"sklearn.mixture.GaussianMixture doesn't sample properly plus a prob with fitting","user":{"login":"Actla","id":9610770,"avatar_url":"https://avatars.githubusercontent.com/u/9610770?v=3","gravatar_id":"","url":"https://api.github.com/users/Actla","html_url":"https://github.com/Actla","followers_url":"https://api.github.com/users/Actla/followers","following_url":"https://api.github.com/users/Actla/following{/other_user}","gists_url":"https://api.github.com/users/Actla/gists{/gist_id}","starred_url":"https://api.github.com/users/Actla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Actla/subscriptions","organizations_url":"https://api.github.com/users/Actla/orgs","repos_url":"https://api.github.com/users/Actla/repos","events_url":"https://api.github.com/users/Actla/events{/privacy}","received_events_url":"https://api.github.com/users/Actla/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":12,"created_at":"2016-11-03T21:23:55Z","updated_at":"2016-11-17T22:33:50Z","closed_at":null,"body":"<!--\r\nIf your issue is a usage question, submit it here instead:\r\n- StackOverflow with the scikit-learn tag: http://stackoverflow.com/questions/tagged/scikit-learn\r\n- Mailing List: https://mail.python.org/mailman/listinfo/scikit-learn\r\nFor more information, see User Questions: http://scikit-learn.org/stable/support.html#user-questions\r\n-->\r\n\r\n<!-- Instructions For Filing a Bug: https://github.com/scikit-learn/scikit-learn/blob/master/CONTRIBUTING.md#filing-bugs -->\r\n\r\n#### Description\r\nthe new sklearn.mixture.GaussianMixture has messed up several things. 2 of them:\r\n- __IMPORTANT__: why can't I sample from a GMM if I don't fit. I want to define all the parameters and to be able to sample from that distribution\r\n  - the trick I use is to specify gmm.precisions_cholesky_ but I find it overcomplicated\r\n- why does it assume that the covariance has to be a 2d matrix and I have to specify \"spherical\" if I am in 1d.\r\n- __IMPORTANT__: the process of sampling gives back fewer samples than it's asked for, 665 instead of 1000. I think its caused by the line 384 in scikit-learn/sklearn/mixture/base.py:\r\n``` python\r\nn_samples_comp = np.round(self.weights_ * n_samples).astype(int)\r\n``` \r\n\r\n<!-- Example: Joblib Error thrown when calling fit on LatentDirichletAllocation with evaluate_every > 0-->\r\n\r\n#### Steps/Code to Reproduce\r\n``` python\r\nimport numpy as np\r\nfrom sklearn.mixture import GaussianMixture\r\nnp.random.seed(0)\r\n\r\n# I define 10 gaussians for the mixture\r\nn_gaussians = 10\r\nmeans = np.array(10*(2*np.random.rand(n_gaussians,1)-1))\r\nweights = np.array(.4*np.random.rand(n_gaussians,1)) ** 2\r\nto_normalize_weights = np.random.rand(n_gaussians,1)\r\ncovars = np.array(to_normalize_weights/np.sum(to_normalize_weights))\r\nprecisions = np.array([ x**(-1) for x in covars ])\r\n\r\ngmm = GaussianMixture(n_gaussians, covariance_type='full')\r\ngmm.means_ = means\r\ngmm.weights_ = weights\r\ngmm.covariances_ = covars\r\ngmm.precisions_cholesky_ = precisions    #otherwise sklearn thinks it's not fit\r\n\r\nsmples = gmm.sample(n_samples=1000)\r\nprint len(smples[0]), len(smples[1])\r\n\r\n```\r\n<!--\r\nExample:\r\n```\r\nfrom sklearn.feature_extraction.text import CountVectorizer\r\nfrom sklearn.decomposition import LatentDirichletAllocation\r\n\r\ndocs = [\"Help I have a bug\" for i in range(1000)]\r\n\r\nvectorizer = CountVectorizer(input=docs, analyzer='word')\r\nlda_features = vectorizer.fit_transform(docs)\r\n\r\nlda_model = LatentDirichletAllocation(\r\n    n_topics=10,\r\n    learning_method='online',\r\n    evaluate_every=10,\r\n    n_jobs=4,\r\n)\r\nmodel = lda_model.fit(lda_features)\r\n```\r\nIf the code is too long, feel free to put it in a public gist and link\r\nit in the issue: https://gist.github.com\r\n-->\r\n\r\n#### Expected Results\r\n<!-- Example: No error is thrown. Please paste or describe the expected results.-->\r\n1000,1000\r\n#### Actual Results\r\n<!-- Please paste or specifically describe the actual output or traceback. -->\r\n665, 665\r\n#### Versions\r\n<!--\r\nPlease run the following snippet and paste the output below.\r\nimport platform; print(platform.platform())\r\nimport sys; print(\"Python\", sys.version)\r\nimport numpy; print(\"NumPy\", numpy.__version__)\r\nimport scipy; print(\"SciPy\", scipy.__version__)\r\nimport sklearn; print(\"Scikit-Learn\", sklearn.__version__)\r\n-->\r\n\r\n\r\n<!-- Thanks for contributing! -->\r\n"},"comment":{"url":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/comments/261391376","html_url":"https://github.com/scikit-learn/scikit-learn/issues/7822#issuecomment-261391376","issue_url":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/7822","id":261391376,"user":{"login":"amueller","id":449558,"avatar_url":"https://avatars.githubusercontent.com/u/449558?v=3","gravatar_id":"","url":"https://api.github.com/users/amueller","html_url":"https://github.com/amueller","followers_url":"https://api.github.com/users/amueller/followers","following_url":"https://api.github.com/users/amueller/following{/other_user}","gists_url":"https://api.github.com/users/amueller/gists{/gist_id}","starred_url":"https://api.github.com/users/amueller/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amueller/subscriptions","organizations_url":"https://api.github.com/users/amueller/orgs","repos_url":"https://api.github.com/users/amueller/repos","events_url":"https://api.github.com/users/amueller/events{/privacy}","received_events_url":"https://api.github.com/users/amueller/received_events","type":"User","site_admin":false},"created_at":"2016-11-17T22:33:50Z","updated_at":"2016-11-17T22:33:50Z","body":"@Actla we definitely don't want to be as far-reaching as we can be. We are already stretched very thin. Maybe also check out pomegranate: https://github.com/jmschrei/pomegranate"}}
{"actor":{"display_login":"amueller"}}