{"action":"created","comment":{"url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/comments/42461641","id":42461641,"diff_hunk":"@@ -8,52 +8,88 @@\n .. currentmodule:: sklearn.linear_model\n \n :class:`Ridge` Regression is the estimator used in this example.\n-Each color represents a different feature of the\n+Each color in the upper plot represents a different feature of the\n coefficient vector, and this is displayed as a function of the\n regularization parameter.\n \n-At the end of the path, as alpha tends toward zero\n-and the solution tends towards the ordinary least squares, coefficients\n-exhibit big oscillations.\n+In this example the dependent variable Y is set as a function\n+of the input features: Y = Xb + e. The coefficient vector b is\n+randomly sampled from a normal distribution.\n+\n+As alpha tends toward zero the coefficients found by Ridge\n+regression stabilize towards the randomly sampled vector b.\n+For big alpha (strong regularisation) the coefficients\n+are smaller (eventually converging at 0) leading to a\n+simpler and biased solution.\n+These dependencies can be observed on the left plot.\n+\n+The right plot shows the mean squared error between the\n+coefficients found by the model and the chosen vector b.\n+Less regularised models find the coefficients without\n+trouble (0 error), stronger regularised models increase\n+the error.\n \"\"\"\n \n-# Author: Fabian Pedregosa -- <fabian.pedregosa@inria.fr>\n-# License: BSD 3 clause\n+# Author: Kornel Kielczewski -- <kornel.k@plusnet.pl>\n \n print(__doc__)\n \n import numpy as np\n import matplotlib.pyplot as plt\n-from sklearn import linear_model\n+from sklearn.linear_model import Ridge\n+from matplotlib import pyplot\n+from sklearn.metrics import mean_squared_error\n+\n+def generate_test_data(N, p):\n+    \"\"\"Generate N samples of p dimensions\"\"\"\n+    features = [np.random.randn(p) for x in range(N)]\n+    b = np.random.normal(size = p)\n+    e = np.random.randn()\n+    e = 0\n+    Y = map(lambda row: sum(row * b) + e, features)","path":"examples/linear_model/plot_ridge_path.py","position":49,"original_position":49,"commit_id":"0c88274fb74e328587219499568dfa3f428e1490","original_commit_id":"0c88274fb74e328587219499568dfa3f428e1490","user":{"login":"Kornel","id":628457,"avatar_url":"https://avatars.githubusercontent.com/u/628457?v=3","gravatar_id":"","url":"https://api.github.com/users/Kornel","html_url":"https://github.com/Kornel","followers_url":"https://api.github.com/users/Kornel/followers","following_url":"https://api.github.com/users/Kornel/following{/other_user}","gists_url":"https://api.github.com/users/Kornel/gists{/gist_id}","starred_url":"https://api.github.com/users/Kornel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Kornel/subscriptions","organizations_url":"https://api.github.com/users/Kornel/orgs","repos_url":"https://api.github.com/users/Kornel/repos","events_url":"https://api.github.com/users/Kornel/events{/privacy}","received_events_url":"https://api.github.com/users/Kornel/received_events","type":"User","site_admin":false},"body":"good one, thanks","created_at":"2015-10-20T07:00:10Z","updated_at":"2015-10-20T07:00:10Z","html_url":"https://github.com/scikit-learn/scikit-learn/pull/5470#discussion_r42461641","pull_request_url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/5470","_links":{"self":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/comments/42461641"},"html":{"href":"https://github.com/scikit-learn/scikit-learn/pull/5470#discussion_r42461641"},"pull_request":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/5470"}}},"pull_request":{"url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/5470","id":48121343,"html_url":"https://github.com/scikit-learn/scikit-learn/pull/5470","diff_url":"https://github.com/scikit-learn/scikit-learn/pull/5470.diff","patch_url":"https://github.com/scikit-learn/scikit-learn/pull/5470.patch","issue_url":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/5470","number":5470,"state":"open","locked":false,"title":"Ridge path - another perspective","user":{"login":"Kornel","id":628457,"avatar_url":"https://avatars.githubusercontent.com/u/628457?v=3","gravatar_id":"","url":"https://api.github.com/users/Kornel","html_url":"https://github.com/Kornel","followers_url":"https://api.github.com/users/Kornel/followers","following_url":"https://api.github.com/users/Kornel/following{/other_user}","gists_url":"https://api.github.com/users/Kornel/gists{/gist_id}","starred_url":"https://api.github.com/users/Kornel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Kornel/subscriptions","organizations_url":"https://api.github.com/users/Kornel/orgs","repos_url":"https://api.github.com/users/Kornel/repos","events_url":"https://api.github.com/users/Kornel/events{/privacy}","received_events_url":"https://api.github.com/users/Kornel/received_events","type":"User","site_admin":false},"body":"I've been looking at the example and found it confusing that we have to set fit_intercept=False. This was because Y = 1, hence an optimal solution exists where the intercept is 1 and all other coefficients are zero. That's why I've decided to play around with this example.\r\n\r\nHere I propose another perspective, where we set Y = bX + e, an solution which is easy to find for the estimator, and two plots: one where we can see how the coefficients are selected properly and another where we see how the error (estimator.coef_ - b) changes.\r\n\r\nWhat do you think?","created_at":"2015-10-19T20:24:21Z","updated_at":"2015-10-20T07:00:10Z","closed_at":null,"merged_at":null,"merge_commit_sha":"58e72720827abd819c466afe400a5156b396c287","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/5470/commits","review_comments_url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/5470/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/5470/comments","statuses_url":"https://api.github.com/repos/scikit-learn/scikit-learn/statuses/0c88274fb74e328587219499568dfa3f428e1490","head":{"label":"Kornel:master","ref":"master","sha":"0c88274fb74e328587219499568dfa3f428e1490","user":{"login":"Kornel","id":628457,"avatar_url":"https://avatars.githubusercontent.com/u/628457?v=3","gravatar_id":"","url":"https://api.github.com/users/Kornel","html_url":"https://github.com/Kornel","followers_url":"https://api.github.com/users/Kornel/followers","following_url":"https://api.github.com/users/Kornel/following{/other_user}","gists_url":"https://api.github.com/users/Kornel/gists{/gist_id}","starred_url":"https://api.github.com/users/Kornel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Kornel/subscriptions","organizations_url":"https://api.github.com/users/Kornel/orgs","repos_url":"https://api.github.com/users/Kornel/repos","events_url":"https://api.github.com/users/Kornel/events{/privacy}","received_events_url":"https://api.github.com/users/Kornel/received_events","type":"User","site_admin":false},"repo":{"id":44137052,"name":"scikit-learn","full_name":"Kornel/scikit-learn","owner":{"login":"Kornel","id":628457,"avatar_url":"https://avatars.githubusercontent.com/u/628457?v=3","gravatar_id":"","url":"https://api.github.com/users/Kornel","html_url":"https://github.com/Kornel","followers_url":"https://api.github.com/users/Kornel/followers","following_url":"https://api.github.com/users/Kornel/following{/other_user}","gists_url":"https://api.github.com/users/Kornel/gists{/gist_id}","starred_url":"https://api.github.com/users/Kornel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Kornel/subscriptions","organizations_url":"https://api.github.com/users/Kornel/orgs","repos_url":"https://api.github.com/users/Kornel/repos","events_url":"https://api.github.com/users/Kornel/events{/privacy}","received_events_url":"https://api.github.com/users/Kornel/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Kornel/scikit-learn","description":"scikit-learn: machine learning in Python","fork":true,"url":"https://api.github.com/repos/Kornel/scikit-learn","forks_url":"https://api.github.com/repos/Kornel/scikit-learn/forks","keys_url":"https://api.github.com/repos/Kornel/scikit-learn/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Kornel/scikit-learn/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Kornel/scikit-learn/teams","hooks_url":"https://api.github.com/repos/Kornel/scikit-learn/hooks","issue_events_url":"https://api.github.com/repos/Kornel/scikit-learn/issues/events{/number}","events_url":"https://api.github.com/repos/Kornel/scikit-learn/events","assignees_url":"https://api.github.com/repos/Kornel/scikit-learn/assignees{/user}","branches_url":"https://api.github.com/repos/Kornel/scikit-learn/branches{/branch}","tags_url":"https://api.github.com/repos/Kornel/scikit-learn/tags","blobs_url":"https://api.github.com/repos/Kornel/scikit-learn/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Kornel/scikit-learn/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Kornel/scikit-learn/git/refs{/sha}","trees_url":"https://api.github.com/repos/Kornel/scikit-learn/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Kornel/scikit-learn/statuses/{sha}","languages_url":"https://api.github.com/repos/Kornel/scikit-learn/languages","stargazers_url":"https://api.github.com/repos/Kornel/scikit-learn/stargazers","contributors_url":"https://api.github.com/repos/Kornel/scikit-learn/contributors","subscribers_url":"https://api.github.com/repos/Kornel/scikit-learn/subscribers","subscription_url":"https://api.github.com/repos/Kornel/scikit-learn/subscription","commits_url":"https://api.github.com/repos/Kornel/scikit-learn/commits{/sha}","git_commits_url":"https://api.github.com/repos/Kornel/scikit-learn/git/commits{/sha}","comments_url":"https://api.github.com/repos/Kornel/scikit-learn/comments{/number}","issue_comment_url":"https://api.github.com/repos/Kornel/scikit-learn/issues/comments{/number}","contents_url":"https://api.github.com/repos/Kornel/scikit-learn/contents/{+path}","compare_url":"https://api.github.com/repos/Kornel/scikit-learn/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Kornel/scikit-learn/merges","archive_url":"https://api.github.com/repos/Kornel/scikit-learn/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Kornel/scikit-learn/downloads","issues_url":"https://api.github.com/repos/Kornel/scikit-learn/issues{/number}","pulls_url":"https://api.github.com/repos/Kornel/scikit-learn/pulls{/number}","milestones_url":"https://api.github.com/repos/Kornel/scikit-learn/milestones{/number}","notifications_url":"https://api.github.com/repos/Kornel/scikit-learn/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Kornel/scikit-learn/labels{/name}","releases_url":"https://api.github.com/repos/Kornel/scikit-learn/releases{/id}","created_at":"2015-10-12T22:13:21Z","updated_at":"2015-10-12T22:13:34Z","pushed_at":"2015-10-19T20:20:34Z","git_url":"git://github.com/Kornel/scikit-learn.git","ssh_url":"git@github.com:Kornel/scikit-learn.git","clone_url":"https://github.com/Kornel/scikit-learn.git","svn_url":"https://github.com/Kornel/scikit-learn","homepage":"http://scikit-learn.org","size":67730,"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":"scikit-learn:master","ref":"master","sha":"74cfca88cf5171af42166e57eec233532ca04779","user":{"login":"scikit-learn","id":365630,"avatar_url":"https://avatars.githubusercontent.com/u/365630?v=3","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,"name":"scikit-learn","full_name":"scikit-learn/scikit-learn","owner":{"login":"scikit-learn","id":365630,"avatar_url":"https://avatars.githubusercontent.com/u/365630?v=3","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},"private":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}","created_at":"2010-08-17T09:43:38Z","updated_at":"2015-10-20T02:07:04Z","pushed_at":"2015-10-20T06:42:08Z","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":137265,"stargazers_count":7917,"watchers_count":7917,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":4709,"mirror_url":null,"open_issues_count":771,"forks":4709,"open_issues":771,"watchers":7917,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/5470"},"html":{"href":"https://github.com/scikit-learn/scikit-learn/pull/5470"},"issue":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/5470"},"comments":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/5470/comments"},"review_comments":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/5470/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/5470/commits"},"statuses":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/statuses/0c88274fb74e328587219499568dfa3f428e1490"}}}}