{"action":"created","comment":{"url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/comments/22544613","id":22544613,"diff_hunk":"@@ -0,0 +1,172 @@\n+\"\"\"\n+=============================================\n+Comparison of kernel ridge regression and SVR\n+=============================================\n+\n+Both kernel ridge regression (KRR) and SVR learn a non-linear function by\n+employing the kernel trick, i.e., they learn a linear function in the space\n+induced by the respective kernel which corresponds to a non-linear function in\n+the original space. They differ in the loss functions (ridge versus \n+epsilon-insensitive loss). In contrast to SVR, fitting a KRR can be done in \n+closed-form and is typically faster for medium-sized datasets. On the other \n+hand, the learned model is non-sparse and thus slower than SVR at \n+prediction-time.\n+\n+This example illustrates both methods on an artificial dataset, which\n+consists of a sinusoidal target function and strong noise added to every fifth\n+datapoint. The first figure compares the learned model of KRR and SVR when both\n+complexity/regularization and bandwidth of the RBF kernel are optimized using\n+grid-search. The learned functions are very similar; however, fitting KRR is\n+approx. seven times faster than fitting SVR (both with grid-search). However,\n+prediction of 100000 target values is more than tree times faster with SVR since\n+it has learned a sparse model using only approx. 1/3 of the 100 training\n+datapoints as support vectors. \n+\n+The next figure compares the time for fitting and prediction of KRR and SVR for\n+different sizes of the training set. Fitting KRR is faster than SVR for medium-\n+sized training sets (less than 1000 samples); however, for larger training sets\n+SVR scales better. With regard to prediction time, SVR is faster than\n+KRR for all sizes of the training set because of the learned sparse\n+solution. Note that the degree of sparsity and thus the prediction time depends\n+on the parameters epsilon and C of the SVR.  \n+\"\"\"\n+\n+# Authors: Jan Hendrik Metzen <jhm@informatik.uni-bremen.de>\n+# License: BSD 3 clause\n+\n+\n+from __future__ import division\n+import time\n+\n+import numpy as np\n+\n+from sklearn.svm import SVR\n+from sklearn.grid_search import GridSearchCV\n+from sklearn.learning_curve import learning_curve\n+from sklearn.kernel_ridge import KernelRidge\n+import matplotlib.pyplot as plt\n+\n+np.random.seed(0)","path":"examples/plot_kernel_ridge_regression.py","position":49,"original_position":49,"commit_id":"75b40bf9371ee7ff2f1899f91e41a9556f99e34f","original_commit_id":"75b40bf9371ee7ff2f1899f91e41a9556f99e34f","user":{"login":"eickenberg","id":1306635,"avatar_url":"https://avatars.githubusercontent.com/u/1306635?v=3","gravatar_id":"","url":"https://api.github.com/users/eickenberg","html_url":"https://github.com/eickenberg","followers_url":"https://api.github.com/users/eickenberg/followers","following_url":"https://api.github.com/users/eickenberg/following{/other_user}","gists_url":"https://api.github.com/users/eickenberg/gists{/gist_id}","starred_url":"https://api.github.com/users/eickenberg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eickenberg/subscriptions","organizations_url":"https://api.github.com/users/eickenberg/orgs","repos_url":"https://api.github.com/users/eickenberg/repos","events_url":"https://api.github.com/users/eickenberg/events{/privacy}","received_events_url":"https://api.github.com/users/eickenberg/received_events","type":"User","site_admin":false},"body":"Generally the use of `rng = np.random.RandomState(seed)` is preferred. Random numbers are then generated with e.g. `gauss = rng.randn(shape)`","created_at":"2015-01-06T19:21:52Z","updated_at":"2015-01-06T19:21:52Z","html_url":"https://github.com/scikit-learn/scikit-learn/pull/3942#discussion_r22544613","pull_request_url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/3942","_links":{"self":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/comments/22544613"},"html":{"href":"https://github.com/scikit-learn/scikit-learn/pull/3942#discussion_r22544613"},"pull_request":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/3942"}}},"pull_request":{"url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/3942","id":25630554,"html_url":"https://github.com/scikit-learn/scikit-learn/pull/3942","diff_url":"https://github.com/scikit-learn/scikit-learn/pull/3942.diff","patch_url":"https://github.com/scikit-learn/scikit-learn/pull/3942.patch","issue_url":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/3942","number":3942,"state":"open","locked":false,"title":"[MRG+1] Kernel Ridge Regression","user":{"login":"jmetzen","id":1116263,"avatar_url":"https://avatars.githubusercontent.com/u/1116263?v=3","gravatar_id":"","url":"https://api.github.com/users/jmetzen","html_url":"https://github.com/jmetzen","followers_url":"https://api.github.com/users/jmetzen/followers","following_url":"https://api.github.com/users/jmetzen/following{/other_user}","gists_url":"https://api.github.com/users/jmetzen/gists{/gist_id}","starred_url":"https://api.github.com/users/jmetzen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jmetzen/subscriptions","organizations_url":"https://api.github.com/users/jmetzen/orgs","repos_url":"https://api.github.com/users/jmetzen/repos","events_url":"https://api.github.com/users/jmetzen/events{/privacy}","received_events_url":"https://api.github.com/users/jmetzen/received_events","type":"User","site_admin":false},"body":"Adds an implementation of Kernel Ridge Regression (KRR)\r\n\r\nBasic implementation of KRR based on @mblondel's code in lightning. In addition to the lighning code, documentation and an example comparing KRR and SVR is added. The example illustrates the models learned by KRR and SVR:\r\n\r\n![plot_kernel_ridge_regression_001](https://cloud.githubusercontent.com/assets/1116263/5330658/9793f8f6-7e03-11e4-93a9-7da2f0634037.png)\r\n\r\nFurthermore, it compares the time required for fitting the model and predicting with the model for different sizes of the training set:\r\n\r\n![plot_kernel_ridge_regression_002](https://cloud.githubusercontent.com/assets/1116263/5330660/a1b7a4cc-7e03-11e4-8628-3d6cccad921a.png)\r\n","created_at":"2014-12-07T10:26:47Z","updated_at":"2015-01-06T19:21:52Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f8a9b66516d4a0a588f10c3a0b91fcb01c9dfb79","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/3942/commits","review_comments_url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/3942/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/3942/comments","statuses_url":"https://api.github.com/repos/scikit-learn/scikit-learn/statuses/75b40bf9371ee7ff2f1899f91e41a9556f99e34f","head":{"label":"jmetzen:kernel_ridge","ref":"kernel_ridge","sha":"75b40bf9371ee7ff2f1899f91e41a9556f99e34f","user":{"login":"jmetzen","id":1116263,"avatar_url":"https://avatars.githubusercontent.com/u/1116263?v=3","gravatar_id":"","url":"https://api.github.com/users/jmetzen","html_url":"https://github.com/jmetzen","followers_url":"https://api.github.com/users/jmetzen/followers","following_url":"https://api.github.com/users/jmetzen/following{/other_user}","gists_url":"https://api.github.com/users/jmetzen/gists{/gist_id}","starred_url":"https://api.github.com/users/jmetzen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jmetzen/subscriptions","organizations_url":"https://api.github.com/users/jmetzen/orgs","repos_url":"https://api.github.com/users/jmetzen/repos","events_url":"https://api.github.com/users/jmetzen/events{/privacy}","received_events_url":"https://api.github.com/users/jmetzen/received_events","type":"User","site_admin":false},"repo":{"id":15583876,"name":"scikit-learn","full_name":"jmetzen/scikit-learn","owner":{"login":"jmetzen","id":1116263,"avatar_url":"https://avatars.githubusercontent.com/u/1116263?v=3","gravatar_id":"","url":"https://api.github.com/users/jmetzen","html_url":"https://github.com/jmetzen","followers_url":"https://api.github.com/users/jmetzen/followers","following_url":"https://api.github.com/users/jmetzen/following{/other_user}","gists_url":"https://api.github.com/users/jmetzen/gists{/gist_id}","starred_url":"https://api.github.com/users/jmetzen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jmetzen/subscriptions","organizations_url":"https://api.github.com/users/jmetzen/orgs","repos_url":"https://api.github.com/users/jmetzen/repos","events_url":"https://api.github.com/users/jmetzen/events{/privacy}","received_events_url":"https://api.github.com/users/jmetzen/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jmetzen/scikit-learn","description":"scikit-learn: machine learning in Python","fork":true,"url":"https://api.github.com/repos/jmetzen/scikit-learn","forks_url":"https://api.github.com/repos/jmetzen/scikit-learn/forks","keys_url":"https://api.github.com/repos/jmetzen/scikit-learn/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jmetzen/scikit-learn/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jmetzen/scikit-learn/teams","hooks_url":"https://api.github.com/repos/jmetzen/scikit-learn/hooks","issue_events_url":"https://api.github.com/repos/jmetzen/scikit-learn/issues/events{/number}","events_url":"https://api.github.com/repos/jmetzen/scikit-learn/events","assignees_url":"https://api.github.com/repos/jmetzen/scikit-learn/assignees{/user}","branches_url":"https://api.github.com/repos/jmetzen/scikit-learn/branches{/branch}","tags_url":"https://api.github.com/repos/jmetzen/scikit-learn/tags","blobs_url":"https://api.github.com/repos/jmetzen/scikit-learn/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jmetzen/scikit-learn/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jmetzen/scikit-learn/git/refs{/sha}","trees_url":"https://api.github.com/repos/jmetzen/scikit-learn/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jmetzen/scikit-learn/statuses/{sha}","languages_url":"https://api.github.com/repos/jmetzen/scikit-learn/languages","stargazers_url":"https://api.github.com/repos/jmetzen/scikit-learn/stargazers","contributors_url":"https://api.github.com/repos/jmetzen/scikit-learn/contributors","subscribers_url":"https://api.github.com/repos/jmetzen/scikit-learn/subscribers","subscription_url":"https://api.github.com/repos/jmetzen/scikit-learn/subscription","commits_url":"https://api.github.com/repos/jmetzen/scikit-learn/commits{/sha}","git_commits_url":"https://api.github.com/repos/jmetzen/scikit-learn/git/commits{/sha}","comments_url":"https://api.github.com/repos/jmetzen/scikit-learn/comments{/number}","issue_comment_url":"https://api.github.com/repos/jmetzen/scikit-learn/issues/comments/{number}","contents_url":"https://api.github.com/repos/jmetzen/scikit-learn/contents/{+path}","compare_url":"https://api.github.com/repos/jmetzen/scikit-learn/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jmetzen/scikit-learn/merges","archive_url":"https://api.github.com/repos/jmetzen/scikit-learn/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jmetzen/scikit-learn/downloads","issues_url":"https://api.github.com/repos/jmetzen/scikit-learn/issues{/number}","pulls_url":"https://api.github.com/repos/jmetzen/scikit-learn/pulls{/number}","milestones_url":"https://api.github.com/repos/jmetzen/scikit-learn/milestones{/number}","notifications_url":"https://api.github.com/repos/jmetzen/scikit-learn/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jmetzen/scikit-learn/labels{/name}","releases_url":"https://api.github.com/repos/jmetzen/scikit-learn/releases{/id}","created_at":"2014-01-02T13:13:12Z","updated_at":"2014-12-20T09:01:52Z","pushed_at":"2014-12-24T12:06:38Z","git_url":"git://github.com/jmetzen/scikit-learn.git","ssh_url":"git@github.com:jmetzen/scikit-learn.git","clone_url":"https://github.com/jmetzen/scikit-learn.git","svn_url":"https://github.com/jmetzen/scikit-learn","homepage":"http://scikit-learn.org","size":57907,"stargazers_count":0,"watchers_count":0,"language":"C","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":"2cfdc1c5fe6b9364356a74fdbb95fa435a22e051","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-01-06T18:12:47Z","pushed_at":"2015-01-06T17:05: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":109169,"stargazers_count":4746,"watchers_count":4746,"language":"C","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2735,"mirror_url":null,"open_issues_count":551,"forks":2735,"open_issues":551,"watchers":4746,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/3942"},"html":{"href":"https://github.com/scikit-learn/scikit-learn/pull/3942"},"issue":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/3942"},"comments":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/3942/comments"},"review_comments":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/3942/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/3942/commits"},"statuses":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/statuses/75b40bf9371ee7ff2f1899f91e41a9556f99e34f"}}}}