GitHub PullRequestReviewCommentEvent at 2014-06-27 13:15:11
Repository: nilearn
Actor: agramfort
Payload: {"action":"created","comment":{"url":"https://api.github.com/repos/nilearn/nilearn/pulls/comments/14291727","id":14291727,"diff_hunk":"@@ -0,0 +1,1217 @@\n+from functools import partial\n+import numpy as np\n+from sklearn.externals.joblib import Memory, Parallel, delayed\n+from sklearn.cross_validation import check_cv\n+from .._utils.fixes.sklearn_center_data import center_data\n+from sklearn.preprocessing import LabelBinarizer\n+from sklearn.metrics import roc_auc_score\n+from .common import _sigmoid\n+from .estimators import (_BaseRegressor, _BaseClassifier, _BaseEstimator,\n+                         SmoothLassoRegressor, SmoothLassoClassifier,\n+                         TVl1Classifier, TVl1Regressor)\n+from .smooth_lasso import smooth_lasso_logistic, smooth_lasso_squared_loss\n+from .tv import tvl1_solver\n+from ._cv_tricks import (EarlyStoppingCallback, RegressorFeatureSelector,\n+                         ClassifierFeatureSelector)\n+\n+\n+def logistic_path_scores(solver, X, y, alphas, l1_ratio, train,\n+                         test, tol=1e-4, max_iter=1000, init=None,\n+                         mask=None, X_std=1., verbose=0, key=None,\n+                         screening_percentile=10., memory=Memory(None),\n+                         **kwargs):\n+    \"\"\"Function to compute scores of different alphas in classification.\n+    used by CV objects.\n+\n+    Parameters\n+    ----------\n+    alphas: list of floats\n+        List of regularization parameters being considered.\n+\n+    l1_ratio : float in the interval [0, 1]; optinal (default .5)\n+        Constant that mixes L1 and TV (resp. Smooth Lasso) penalization.\n+        l1_ratio == 0: just smooth. l1_ratio == 1: just lasso.\n+\n+    solver: function handle\n+       See for example tv.TVl1Classifier documenetation.\n+\n+    \"\"\"\n+\n+    # ANOVA screening\n+    selector = ClassifierFeatureSelector(percentile=screening_percentile,\n+                                         mask=mask)\n+    X = selector.fit_transform(X, y)\n+    mask = selector.mask_\n+\n+    X_train, y_train = X[train], y[train]\n+    X_test, y_test = X[test], y[test]\n+    test_scores = []\n+\n+    def _test_score(w):\n+        return 1. - roc_auc_score(\n+            (y_test > 0.), _sigmoid(np.dot(X_test, w[:-1]) + w[-1]))\n+\n+    # setup callback mechanisim for ealry stopping\n+    callerback = EarlyStoppingCallback(X_test, y_test, X_std, verbose=verbose)\n+    env = dict(counter=0)\n+\n+    def _callback(_env):\n+        if not isinstance(_env, dict):\n+            _env = dict(w=w)\n+\n+        _env['w'] = _env['w'][:-1]  # strip off intercept\n+        env[\"counter\"] += 1\n+        _env[\"counter\"] = env[\"counter\"]\n+\n+        return callerback(_env)\n+\n+    best_score = np.inf\n+    for alpha in alphas:\n+        w, _, init = solver(\n+            X_train, y_train, alpha, l1_ratio, mask=mask, tol=tol,\n+            max_iter=max_iter, init=init, verbose=verbose, callback=_callback,\n+            **kwargs)\n+        score = _test_score(w)\n+        test_scores.append(score)\n+        if score <= best_score:\n+            best_score = score\n+            best_alpha = alpha\n+\n+    # Re-fit best model to high precision (i.e without early stopping, etc.).\n+    # N.B: This work is cached, just in case another worker on another fold\n+    # reports the same best alpha.\n+    best_w, _, init = memory.cache(solver)(\n+        X, y, best_alpha, l1_ratio, mask=mask, tol=tol,\n+        max_iter=max_iter, init=init, verbose=verbose, **kwargs)\n+\n+    # Unmask ANOVA screening\n+    best_w = selector.unmask(best_w)\n+\n+    return test_scores, best_w, key\n+\n+\n+def squared_loss_path_scores(solver, X, y, alphas, l1_ratio, train, test,\n+                             tol=1e-4, max_iter=1000, init=None, mask=None,\n+                             debias=False, X_std=1., ymean=0., verbose=0,\n+                             key=None, screening_percentile=10.,\n+                             memory=Memory(None), **kwargs):\n+    \"\"\"Function to compute scores of different alphas in regression.\n+    used by CV objects.\n+\n+    \"\"\"\n+\n+    # ANOVA screenin\n+    selector = RegressorFeatureSelector(percentile=screening_percentile,\n+                                        mask=mask)\n+    X = selector.fit_transform(X, y)\n+    mask = selector.mask_\n+\n+    # make train / test datasets\n+    X_train, y_train = X[train], y[train]\n+    X_test, y_test = X[test], y[test]\n+\n+    def _test_score(w):\n+        \"\"\"Helper function to compute score of model with given wieghts map (\n+        loadings vector).\n+\n+        \"\"\"\n+\n+        # debias to correct for DoF\n+        if debias:\n+            y_pred = np.dot(X_test, w)\n+            scaling = np.dot(y_pred, y_pred)\n+            if scaling > 0.:\n+                scaling = np.dot(y_pred, y_test) / scaling\n+                w *= scaling\n+        y_pred = np.dot(X_test, w) + ymean  # don't forget to add intercept!\n+        score = .5 * np.mean((y_test - y_pred) ** 2)\n+        return score\n+\n+    # setup callback mechanisim for ealry stopping\n+    callerback = EarlyStoppingCallback(X_test, y_test, X_std, verbose=verbose)\n+    env = dict(counter=0)\n+\n+    def _callback(_env):\n+        if not isinstance(_env, dict):\n+            _env = dict(w=_env)\n+\n+        env[\"counter\"] += 1\n+        _env[\"counter\"] = env[\"counter\"]\n+\n+        return callerback(_env)\n+\n+    # rumble down regularization path (with warm-starts)\n+    test_scores = []\n+    best_score = np.inf\n+    for alpha in alphas:\n+        w, _, init = solver(","path":"nilearn/sparse_models/cv.py","position":147,"original_position":147,"commit_id":"d37b28019955490d45da35f0a7e65379ad1b88f0","original_commit_id":"9984b41d1366ee9664d2613b4a861492021da7e2","user":{"login":"agramfort","id":161052,"avatar_url":"https://avatars.githubusercontent.com/u/161052?","gravatar_id":"e9758ca665b8c3d8cb3026c114d05833","url":"https://api.github.com/users/agramfort","html_url":"https://github.com/agramfort","followers_url":"https://api.github.com/users/agramfort/followers","following_url":"https://api.github.com/users/agramfort/following{/other_user}","gists_url":"https://api.github.com/users/agramfort/gists{/gist_id}","starred_url":"https://api.github.com/users/agramfort/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/agramfort/subscriptions","organizations_url":"https://api.github.com/users/agramfort/orgs","repos_url":"https://api.github.com/users/agramfort/repos","events_url":"https://api.github.com/users/agramfort/events{/privacy}","received_events_url":"https://api.github.com/users/agramfort/received_events","type":"User","site_admin":false},"body":"cache?","created_at":"2014-06-27T13:15:11Z","updated_at":"2014-06-27T13:15:11Z","html_url":"https://github.com/nilearn/nilearn/pull/219#discussion_r14291727","pull_request_url":"https://api.github.com/repos/nilearn/nilearn/pulls/219","_links":{"self":{"href":"https://api.github.com/repos/nilearn/nilearn/pulls/comments/14291727"},"html":{"href":"https://github.com/nilearn/nilearn/pull/219#discussion_r14291727"},"pull_request":{"href":"https://api.github.com/repos/nilearn/nilearn/pulls/219"}}},"pull_request":{"url":"https://api.github.com/repos/nilearn/nilearn/pulls/219","id":17693110,"html_url":"https://github.com/nilearn/nilearn/pull/219","diff_url":"https://github.com/nilearn/nilearn/pull/219.diff","patch_url":"https://github.com/nilearn/nilearn/pull/219.patch","issue_url":"https://api.github.com/repos/nilearn/nilearn/issues/219","number":219,"state":"open","title":"(WIP) Sparse models: S-LASSO and TV-l1","user":{"login":"dohmatob","id":634068,"avatar_url":"https://avatars.githubusercontent.com/u/634068?","gravatar_id":"3f99b639fc16183758ab2b38bca26ee4","url":"https://api.github.com/users/dohmatob","html_url":"https://github.com/dohmatob","followers_url":"https://api.github.com/users/dohmatob/followers","following_url":"https://api.github.com/users/dohmatob/following{/other_user}","gists_url":"https://api.github.com/users/dohmatob/gists{/gist_id}","starred_url":"https://api.github.com/users/dohmatob/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dohmatob/subscriptions","organizations_url":"https://api.github.com/users/dohmatob/orgs","repos_url":"https://api.github.com/users/dohmatob/repos","events_url":"https://api.github.com/users/dohmatob/events{/privacy}","received_events_url":"https://api.github.com/users/dohmatob/received_events","type":"User","site_admin":false},"body":"- Supports TV-l1 and S-LASSO priors\r\n- Supports logistic and squared losses\r\n- Has cross validation\r\n- Can automatically select alpha by CV (+ automatic computation of useful alpha ranges for the CV)\r\n- Warning: User must supply l1_ratio","created_at":"2014-06-27T09:16:58Z","updated_at":"2014-06-27T13:15:11Z","closed_at":null,"merged_at":null,"merge_commit_sha":"6a9c89ed5e774a000208d7396f53303da1c1e2df","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/nilearn/nilearn/pulls/219/commits","review_comments_url":"https://api.github.com/repos/nilearn/nilearn/pulls/219/comments","review_comment_url":"https://api.github.com/repos/nilearn/nilearn/pulls/comments/{number}","comments_url":"https://api.github.com/repos/nilearn/nilearn/issues/219/comments","statuses_url":"https://api.github.com/repos/nilearn/nilearn/statuses/d37b28019955490d45da35f0a7e65379ad1b88f0","head":{"label":"dohmatob:sparse-models","ref":"sparse-models","sha":"d37b28019955490d45da35f0a7e65379ad1b88f0","user":{"login":"dohmatob","id":634068,"avatar_url":"https://avatars.githubusercontent.com/u/634068?","gravatar_id":"3f99b639fc16183758ab2b38bca26ee4","url":"https://api.github.com/users/dohmatob","html_url":"https://github.com/dohmatob","followers_url":"https://api.github.com/users/dohmatob/followers","following_url":"https://api.github.com/users/dohmatob/following{/other_user}","gists_url":"https://api.github.com/users/dohmatob/gists{/gist_id}","starred_url":"https://api.github.com/users/dohmatob/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dohmatob/subscriptions","organizations_url":"https://api.github.com/users/dohmatob/orgs","repos_url":"https://api.github.com/users/dohmatob/repos","events_url":"https://api.github.com/users/dohmatob/events{/privacy}","received_events_url":"https://api.github.com/users/dohmatob/received_events","type":"User","site_admin":false},"repo":{"id":10718029,"name":"nilearn","full_name":"dohmatob/nilearn","owner":{"login":"dohmatob","id":634068,"avatar_url":"https://avatars.githubusercontent.com/u/634068?","gravatar_id":"3f99b639fc16183758ab2b38bca26ee4","url":"https://api.github.com/users/dohmatob","html_url":"https://github.com/dohmatob","followers_url":"https://api.github.com/users/dohmatob/followers","following_url":"https://api.github.com/users/dohmatob/following{/other_user}","gists_url":"https://api.github.com/users/dohmatob/gists{/gist_id}","starred_url":"https://api.github.com/users/dohmatob/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dohmatob/subscriptions","organizations_url":"https://api.github.com/users/dohmatob/orgs","repos_url":"https://api.github.com/users/dohmatob/repos","events_url":"https://api.github.com/users/dohmatob/events{/privacy}","received_events_url":"https://api.github.com/users/dohmatob/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/dohmatob/nilearn","description":"NeuroImaging with the Scikit-learn: fMRI inverse inference tutorial","fork":true,"url":"https://api.github.com/repos/dohmatob/nilearn","forks_url":"https://api.github.com/repos/dohmatob/nilearn/forks","keys_url":"https://api.github.com/repos/dohmatob/nilearn/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dohmatob/nilearn/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dohmatob/nilearn/teams","hooks_url":"https://api.github.com/repos/dohmatob/nilearn/hooks","issue_events_url":"https://api.github.com/repos/dohmatob/nilearn/issues/events{/number}","events_url":"https://api.github.com/repos/dohmatob/nilearn/events","assignees_url":"https://api.github.com/repos/dohmatob/nilearn/assignees{/user}","branches_url":"https://api.github.com/repos/dohmatob/nilearn/branches{/branch}","tags_url":"https://api.github.com/repos/dohmatob/nilearn/tags","blobs_url":"https://api.github.com/repos/dohmatob/nilearn/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dohmatob/nilearn/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dohmatob/nilearn/git/refs{/sha}","trees_url":"https://api.github.com/repos/dohmatob/nilearn/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dohmatob/nilearn/statuses/{sha}","languages_url":"https://api.github.com/repos/dohmatob/nilearn/languages","stargazers_url":"https://api.github.com/repos/dohmatob/nilearn/stargazers","contributors_url":"https://api.github.com/repos/dohmatob/nilearn/contributors","subscribers_url":"https://api.github.com/repos/dohmatob/nilearn/subscribers","subscription_url":"https://api.github.com/repos/dohmatob/nilearn/subscription","commits_url":"https://api.github.com/repos/dohmatob/nilearn/commits{/sha}","git_commits_url":"https://api.github.com/repos/dohmatob/nilearn/git/commits{/sha}","comments_url":"https://api.github.com/repos/dohmatob/nilearn/comments{/number}","issue_comment_url":"https://api.github.com/repos/dohmatob/nilearn/issues/comments/{number}","contents_url":"https://api.github.com/repos/dohmatob/nilearn/contents/{+path}","compare_url":"https://api.github.com/repos/dohmatob/nilearn/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dohmatob/nilearn/merges","archive_url":"https://api.github.com/repos/dohmatob/nilearn/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dohmatob/nilearn/downloads","issues_url":"https://api.github.com/repos/dohmatob/nilearn/issues{/number}","pulls_url":"https://api.github.com/repos/dohmatob/nilearn/pulls{/number}","milestones_url":"https://api.github.com/repos/dohmatob/nilearn/milestones{/number}","notifications_url":"https://api.github.com/repos/dohmatob/nilearn/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dohmatob/nilearn/labels{/name}","releases_url":"https://api.github.com/repos/dohmatob/nilearn/releases{/id}","created_at":"2013-06-16T09:21:03Z","updated_at":"2014-06-27T06:59:57Z","pushed_at":"2014-06-27T12:46:59Z","git_url":"git://github.com/dohmatob/nilearn.git","ssh_url":"git@github.com:dohmatob/nilearn.git","clone_url":"https://github.com/dohmatob/nilearn.git","svn_url":"https://github.com/dohmatob/nilearn","homepage":"http://nilearn.github.com/","size":4845,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"nilearn:master","ref":"master","sha":"6e150c0b546139237c7a8094093f7d07dadadb9c","user":{"login":"nilearn","id":4646912,"avatar_url":"https://avatars.githubusercontent.com/u/4646912?","gravatar_id":"8b35c948467638a5527d0bad1de7880e","url":"https://api.github.com/users/nilearn","html_url":"https://github.com/nilearn","followers_url":"https://api.github.com/users/nilearn/followers","following_url":"https://api.github.com/users/nilearn/following{/other_user}","gists_url":"https://api.github.com/users/nilearn/gists{/gist_id}","starred_url":"https://api.github.com/users/nilearn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nilearn/subscriptions","organizations_url":"https://api.github.com/users/nilearn/orgs","repos_url":"https://api.github.com/users/nilearn/repos","events_url":"https://api.github.com/users/nilearn/events{/privacy}","received_events_url":"https://api.github.com/users/nilearn/received_events","type":"Organization","site_admin":false},"repo":{"id":1235740,"name":"nilearn","full_name":"nilearn/nilearn","owner":{"login":"nilearn","id":4646912,"avatar_url":"https://avatars.githubusercontent.com/u/4646912?","gravatar_id":"8b35c948467638a5527d0bad1de7880e","url":"https://api.github.com/users/nilearn","html_url":"https://github.com/nilearn","followers_url":"https://api.github.com/users/nilearn/followers","following_url":"https://api.github.com/users/nilearn/following{/other_user}","gists_url":"https://api.github.com/users/nilearn/gists{/gist_id}","starred_url":"https://api.github.com/users/nilearn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nilearn/subscriptions","organizations_url":"https://api.github.com/users/nilearn/orgs","repos_url":"https://api.github.com/users/nilearn/repos","events_url":"https://api.github.com/users/nilearn/events{/privacy}","received_events_url":"https://api.github.com/users/nilearn/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/nilearn/nilearn","description":"Machine learning for NeuroImaging in Python","fork":false,"url":"https://api.github.com/repos/nilearn/nilearn","forks_url":"https://api.github.com/repos/nilearn/nilearn/forks","keys_url":"https://api.github.com/repos/nilearn/nilearn/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nilearn/nilearn/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nilearn/nilearn/teams","hooks_url":"https://api.github.com/repos/nilearn/nilearn/hooks","issue_events_url":"https://api.github.com/repos/nilearn/nilearn/issues/events{/number}","events_url":"https://api.github.com/repos/nilearn/nilearn/events","assignees_url":"https://api.github.com/repos/nilearn/nilearn/assignees{/user}","branches_url":"https://api.github.com/repos/nilearn/nilearn/branches{/branch}","tags_url":"https://api.github.com/repos/nilearn/nilearn/tags","blobs_url":"https://api.github.com/repos/nilearn/nilearn/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nilearn/nilearn/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nilearn/nilearn/git/refs{/sha}","trees_url":"https://api.github.com/repos/nilearn/nilearn/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nilearn/nilearn/statuses/{sha}","languages_url":"https://api.github.com/repos/nilearn/nilearn/languages","stargazers_url":"https://api.github.com/repos/nilearn/nilearn/stargazers","contributors_url":"https://api.github.com/repos/nilearn/nilearn/contributors","subscribers_url":"https://api.github.com/repos/nilearn/nilearn/subscribers","subscription_url":"https://api.github.com/repos/nilearn/nilearn/subscription","commits_url":"https://api.github.com/repos/nilearn/nilearn/commits{/sha}","git_commits_url":"https://api.github.com/repos/nilearn/nilearn/git/commits{/sha}","comments_url":"https://api.github.com/repos/nilearn/nilearn/comments{/number}","issue_comment_url":"https://api.github.com/repos/nilearn/nilearn/issues/comments/{number}","contents_url":"https://api.github.com/repos/nilearn/nilearn/contents/{+path}","compare_url":"https://api.github.com/repos/nilearn/nilearn/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nilearn/nilearn/merges","archive_url":"https://api.github.com/repos/nilearn/nilearn/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nilearn/nilearn/downloads","issues_url":"https://api.github.com/repos/nilearn/nilearn/issues{/number}","pulls_url":"https://api.github.com/repos/nilearn/nilearn/pulls{/number}","milestones_url":"https://api.github.com/repos/nilearn/nilearn/milestones{/number}","notifications_url":"https://api.github.com/repos/nilearn/nilearn/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nilearn/nilearn/labels{/name}","releases_url":"https://api.github.com/repos/nilearn/nilearn/releases{/id}","created_at":"2011-01-09T19:02:23Z","updated_at":"2014-06-23T09:01:53Z","pushed_at":"2014-06-23T09:01:50Z","git_url":"git://github.com/nilearn/nilearn.git","ssh_url":"git@github.com:nilearn/nilearn.git","clone_url":"https://github.com/nilearn/nilearn.git","svn_url":"https://github.com/nilearn/nilearn","homepage":"http://nilearn.github.io","size":7979,"stargazers_count":54,"watchers_count":54,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"forks_count":40,"mirror_url":null,"open_issues_count":39,"forks":40,"open_issues":39,"watchers":54,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/nilearn/nilearn/pulls/219"},"html":{"href":"https://github.com/nilearn/nilearn/pull/219"},"issue":{"href":"https://api.github.com/repos/nilearn/nilearn/issues/219"},"comments":{"href":"https://api.github.com/repos/nilearn/nilearn/issues/219/comments"},"review_comments":{"href":"https://api.github.com/repos/nilearn/nilearn/pulls/219/comments"},"review_comment":{"href":"https://api.github.com/repos/nilearn/nilearn/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/nilearn/nilearn/pulls/219/commits"},"statuses":{"href":"https://api.github.com/repos/nilearn/nilearn/statuses/d37b28019955490d45da35f0a7e65379ad1b88f0"}}}}