GitHub PullRequestReviewCommentEvent at 2014-01-14 10:17:09
Repository: scikit-learn
Actor: agramfort
Payload: {"comment":{"url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/comments/8855163","id":8855163,"diff_hunk":"@@ -1503,3 +1601,257 @@ def __init__(self, alpha=1.0, fit_intercept=True, normalize=False,\n         self.tol = tol\n         self.warm_start = warm_start\n         self.l1_ratio = 1.0\n+\n+\n+class MultiTaskElasticNetCV(LinearModelCV, RegressorMixin):\n+    \"\"\"Multi-task L1/L2 ElasticNet with built-in cross-validation.\n+\n+    The optimization objective for MultiTaskElasticNet is::\n+\n+        (1 / (2 * n_samples)) * ||Y - XW||^Fro_2\n+        + alpha * l1_ratio * ||W||_21\n+        + 0.5 * alpha * (1 - l1_ratio) * ||W||_Fro^2\n+\n+    Where::\n+\n+        ||W||_21 = \\sum_i \\sqrt{\\sum_j w_{ij}^2}\n+\n+    i.e. the sum of norm of each row.\n+\n+    Parameters\n+    ----------\n+    eps : float, optional\n+        Length of the path. ``eps=1e-3`` means that\n+        ``alpha_min / alpha_max = 1e-3``.\n+\n+    alphas : array-like, optional\n+        List of alphas where to compute the models.\n+        If not provided, set automatically.\n+\n+    precompute : True | False | 'auto' | array-like\n+        Whether to use a precomputed Gram matrix to speed up\n+        calculations. If set to ``'auto'`` let us decide. The Gram\n+        matrix can also be passed as argument.\n+\n+    n_alphas : int, optional\n+        Number of alphas along the regularization path\n+\n+    l1_ratio : float or array of floats\n+        The ElasticNet mixing parameter, with 0 < l1_ratio <= 1.\n+        For l1_ratio = 0 the penalty is an L1/L2 penalty. For l1_ratio = 1 it\n+        is an L1 penalty.\n+        For ``0 < l1_ratio < 1``, the penalty is a combination of L1/L2 and L2.\n+\n+    fit_intercept : boolean\n+        whether to calculate the intercept for this model. If set\n+        to false, no intercept will be used in calculations\n+        (e.g. data is expected to be already centered).\n+\n+    normalize : boolean, optional, default False\n+        If ``True``, the regressors X will be normalized before regression.\n+\n+    copy_X : boolean, optional, default True\n+        If ``True``, X will be copied; else, it may be overwritten.\n+\n+    max_iter : int, optional\n+        The maximum number of iterations\n+\n+    tol : float, optional\n+        The tolerance for the optimization: if the updates are\n+        smaller than ``tol``, the optimization code checks the\n+        dual gap for optimality and continues until it is smaller\n+        than ``tol``.\n+\n+    cv : integer or cross-validation generator, optional\n+        If an integer is passed, it is the number of fold (default 3).\n+        Specific cross-validation objects can be passed, see the\n+        :mod:`sklearn.cross_validation` module for the list of possible\n+        objects.\n+\n+    verbose : bool or integer\n+        Amount of verbosity.\n+\n+    n_jobs : integer, optional\n+        Number of CPUs to use during the cross validation. If ``-1``, use\n+        all the CPUs. Note that this is used only if multiple values for\n+        l1_ratio are given.\n+\n+    Attributes\n+    ----------\n+    ``intercept_`` : array, shape = (n_tasks,)\n+        Independent term in decision function.\n+\n+    ``coef_`` : array, shape = (n_tasks, n_features)\n+        Parameter vector (W in the cost function formula).\n+\n+    ``alpha_`` : float\n+        The amount of penalization chosen by cross validation\n+\n+    ``mse_path_`` : array, shape = (n_alphas, n_folds)\n+        mean square error for the test set on each fold, varying alpha\n+\n+    ``alphas_`` : numpy array, shape = (n_alphas,) or (n_alphas*n_l1_ratio)\n+        The grid of alphas used for fitting.\n+        If provided, alphas_ is a 1-D array of shape n_alphas, else it is\n+        of shape of n_alphas*n_l1_ratio since a grid of alphas is fit for\n+        each l1_ratio\n+\n+    ``l1_ratio_`` : float\n+        best l1_ratio obtained by cross-validation.\n+\n+    Examples\n+    --------\n+    >>> from sklearn import linear_model\n+    >>> clf = linear_model.MultiTaskElasticNetCV()\n+    >>> clf.fit([[0,0], [1, 1], [2, 2]],\n+    ...         [[0, 0], [1, 1], [2, 2]])\n+    ... #doctest: +NORMALIZE_WHITESPACE\n+    MultiTaskElasticNetCV(alphas=None, copy_X=True, cv=None, eps=0.001,\n+           fit_intercept=True, l1_ratio=0.5, max_iter=1000, n_alphas=100,\n+           n_jobs=1, normalize=False, precompute='auto', tol=0.0001,\n+           verbose=0)\n+    >>> print(clf.coef_)\n+    [[ 0.52875032  0.46958558]\n+     [ 0.52875032  0.46958558]]\n+    >>> print(clf.intercept_)\n+    [ 0.00166409  0.00166409]\n+\n+    See also\n+    --------\n+    MultiTaskElasticNet\n+    ElasticNetCV\n+    MultiTaskLassoCV\n+\n+    Notes\n+    -----\n+    The algorithm used to fit the model is coordinate descent.\n+\n+    To avoid unnecessary memory duplication the X argument of the fit method\n+    should be directly passed as a Fortran-contiguous numpy array.\n+    \"\"\"\n+    path = staticmethod(enet_path)\n+\n+    def __init__(self, l1_ratio=0.5, eps=1e-3, n_alphas=100, alphas=None,\n+                 fit_intercept=True, normalize=False, precompute='auto',\n+                 max_iter=1000, tol=1e-4, cv=None, copy_X=True,\n+                 verbose=0, n_jobs=1):\n+        self.l1_ratio = l1_ratio\n+        self.eps = eps\n+        self.n_alphas = n_alphas\n+        self.alphas = alphas\n+        self.fit_intercept = fit_intercept\n+        self.normalize = normalize\n+        self.precompute = precompute\n+        self.max_iter = max_iter\n+        self.tol = tol\n+        self.cv = cv\n+        self.copy_X = copy_X\n+        self.verbose = verbose\n+        self.n_jobs = n_jobs\n+\n+\n+class MultiTaskLassoCV(MultiTaskElasticNetCV):\n+    \"\"\"Multi-task L1/L2 Lasso with built-in cross-validation.\n+\n+    The optimization objective for MultiTaskLasso is::\n+\n+        (1 / (2 * n_samples)) * ||Y - XW||^Fro_2 + alpha * ||W||_21\n+\n+    Where::\n+\n+        ||W||_21 = \\sum_i \\sqrt{\\sum_j w_{ij}^2}\n+\n+    i.e. the sum of norm of each row.\n+\n+    Parameters\n+    ----------\n+    eps : float, optional\n+        Length of the path. ``eps=1e-3`` means that\n+        ``alpha_min / alpha_max = 1e-3``.\n+\n+    alphas : array-like, optional\n+        List of alphas where to compute the models.\n+        If not provided, set automaticlly.\n+\n+    precompute : True | False | 'auto' | array-like\n+        Whether to use a precomputed Gram matrix to speed up\n+        calculations. If set to ``'auto'`` let us decide. The Gram\n+        matrix can also be passed as argument.\n+\n+    n_alphas : int, optional\n+        Number of alphas along the regularization path\n+\n+    fit_intercept : boolean\n+        whether to calculate the intercept for this model. If set\n+        to false, no intercept will be used in calculations\n+        (e.g. data is expected to be already centered).\n+\n+    normalize : boolean, optional, default False\n+        If ``True``, the regressors X will be normalized before regression.\n+\n+    copy_X : boolean, optional, default True\n+        If ``True``, X will be copied; else, it may be overwritten.\n+\n+    max_iter : int, optional\n+        The maximum number of iterations.\n+\n+    tol : float, optional\n+        The tolerance for the optimization: if the updates are\n+        smaller than ``tol``, the optimization code checks the\n+        dual gap for optimality and continues until it is smaller\n+        than ``tol``.\n+\n+    cv : integer or cross-validation generator, optional\n+        If an integer is passed, it is the number of fold (default 3).\n+        Specific cross-validation objects can be passed, see the\n+        :mod:`sklearn.cross_validation` module for the list of possible\n+        objects.\n+\n+    verbose : bool or integer\n+        Amount of verbosity.\n+\n+    n_jobs : integer, optional\n+        Number of CPUs to use during the cross validation. If ``-1``, use\n+        all the CPUs. Note that this is used only if multiple values for\n+        l1_ratio are given.\n+\n+    Attributes\n+    ----------\n+    ``intercept_`` : array, shape = (n_tasks,)","path":"sklearn/linear_model/coordinate_descent.py","position":657,"original_position":784,"commit_id":"1f963813c37cf07a60a182020f687213486db3d1","original_commit_id":"264854ed23b183d9287b159a17b68cb0758cae29","user":{"login":"agramfort","id":161052,"avatar_url":"https://gravatar.com/avatar/e9758ca665b8c3d8cb3026c114d05833?d=https%3A%2F%2Fidenticons.github.com%2F3bf21a35133be965b3b9ad779b3c510b.png&r=x","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":"numpy convention is without =. We used to have this = and but when we spot them we now remove them.","created_at":"2014-01-14T10:17:09Z","updated_at":"2014-01-14T10:17:09Z","html_url":"https://github.com/scikit-learn/scikit-learn/pull/2598#discussion_r8855163","pull_request_url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/2598","_links":{"self":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/comments/8855163"},"html":{"href":"https://github.com/scikit-learn/scikit-learn/pull/2598#discussion_r8855163"},"pull_request":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/2598"}}}}