{"action":"created","issue":{"url":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/7439","repository_url":"https://api.github.com/repos/scikit-learn/scikit-learn","labels_url":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/7439/labels{/name}","comments_url":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/7439/comments","events_url":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/7439/events","html_url":"https://github.com/scikit-learn/scikit-learn/issues/7439","id":177224364,"number":7439,"title":"LDA: ellipses for confidence intervals: error in the doc?","user":{"login":"JPFrancoia","id":2399090,"avatar_url":"https://avatars.githubusercontent.com/u/2399090?v=3","gravatar_id":"","url":"https://api.github.com/users/JPFrancoia","html_url":"https://github.com/JPFrancoia","followers_url":"https://api.github.com/users/JPFrancoia/followers","following_url":"https://api.github.com/users/JPFrancoia/following{/other_user}","gists_url":"https://api.github.com/users/JPFrancoia/gists{/gist_id}","starred_url":"https://api.github.com/users/JPFrancoia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JPFrancoia/subscriptions","organizations_url":"https://api.github.com/users/JPFrancoia/orgs","repos_url":"https://api.github.com/users/JPFrancoia/repos","events_url":"https://api.github.com/users/JPFrancoia/events{/privacy}","received_events_url":"https://api.github.com/users/JPFrancoia/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-09-15T16:29:38Z","updated_at":"2016-09-15T23:06:30Z","closed_at":null,"body":"Hi,\r\n\r\nI'm not reporting a bug in the code, but rather something that might be an error in the doc. I also opened a question on SO.\r\n\r\nI'll copy/paste it here and give additional details:\r\n\r\n# TL;DR\r\n\r\nTo plot confidence intervals after a LDA analysis:\r\nShould I use the covariance matrix shared by all classes (```lda.covariance_```), or should I calculate and use the covariance matrix of each class ?\r\n\r\n# Long explanation\r\n\r\nSome time ago, I asked a question about how to draw ellipses around points: http://stackoverflow.com/questions/30682179/draw-ellipses-around-points\r\n\r\nThese ellipses will represent confidence intervals for Linear Discriminant Analysis (LDA) data points.\r\n\r\nI will reuse my old picture, which I got from a scientific publication:\r\n\r\n[![enter image description here][1]][1]\r\n\r\n\r\nThe red points (for example) could be defined as follow, after the LDA calculations:\r\n\r\n    [[-23.88315146  -3.26328266]  # first point\r\n     [-25.94906669  -1.47440904]  # second point\r\n     [-26.52423229  -4.84947907]]  # third point\r\n\r\nYou can see on the picture that the red points are surrounded by an ellipse, which represents the confidence interval (at a certain level) for the mean of the red points.\r\n\r\nThis is what I would like to obtain. Now scikit-learn's doc has an example about that ([here][2]):\r\n\r\n    def plot_ellipse(splot, mean, cov, color):\r\n        v, w = linalg.eigh(cov)\r\n        u = w[0] / linalg.norm(w[0])\r\n        angle = np.arctan(u[1] / u[0])\r\n        angle = 180 * angle / np.pi  # convert to degrees\r\n        # filled Gaussian at 2 standard deviation\r\n        ell = mpl.patches.Ellipse(mean, 2 * v[0] ** 0.5, 2 * v[1] ** 0.5,\r\n                                  180 + angle, color=color)\r\n\r\n\r\nAnd this function is called like this:\r\n\r\n    plot_ellipse(splot, lda.means_[0], lda.covariance_, 'red')\r\n\r\nIn the doc's example, ```plot_ellipse``` is called to draw the confidence interval of all the classes, always with the same covariance: ```lda.covariance```.\r\n\r\nFrom scikit-learn's doc:\r\n\r\n```\r\nlda.covariance\r\nCovariance matrix (shared by all classes)\r\n```\r\n\r\n```lda.covariance``` is then used to determine the angle of the ellipses. As ```lda.covariance``` never changes, all the ellipses will have the same angle.\r\n\r\nIs it mathematically correct to do that ? I am tempted to say no.\r\n\r\nOn another post (http://stackoverflow.com/questions/12301071/multidimensional-confidence-intervals), which is not related to LDA, Joe Kington simply uses (based on a published article) a \" 2-sigma ellipse of the scatter of points\". He calculates the covariance for each class:\r\n\r\n    cov = np.cov(points, rowvar=False)\r\n\r\n, where ```points``` would be the 3 points described above, for example. He then uses a similar way to calculate the angle of the ellipses. But as he calculates the covariance matrix for each class, the angles of the ellipses are not the same across the classes.\r\n\r\n\r\n\r\n  [1]: http://i.stack.imgur.com/XH2oH.png\r\n  [2]: http://scikit-learn.org/stable/auto_examples/classification/plot_lda_qda.html"},"comment":{"url":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/comments/247479396","html_url":"https://github.com/scikit-learn/scikit-learn/issues/7439#issuecomment-247479396","issue_url":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/7439","id":247479396,"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-09-15T23:06:30Z","updated_at":"2016-09-15T23:06:30Z","body":"Where does it say in the example that this is a confidence interval?\r\nLDA fits Gaussians per class that share a single covariance matrix.\r\n\r\nWhat's the definition of confidence region for a classifier? That's not a concept I'm familiar with.\r\nA 95% confidence interval or region is a region that contains an unobserved parameter 95% of the time.\r\nWhat would be the unobserved parameter here? The true class mean?"}}
{"actor":{"display_login":"amueller"}}