Sklearn, LassoCV () and ElasticCV () broken?

sklearn provides the LASSO method for estimating regression. However, when I try to install LassoCV (X, y) with a y matrix, it throws an error. See the screenshot below and the link for their documentation. The sklearn version I'm using is 0.15.2.

http://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LassoCV.html#sklearn.linear_model.LassoCV

His doc says y can be ndarray:

y : array-like, shape (n_samples,) or (n_samples, n_targets) 

When I use only Lasso () to match the same X, and y, it works fine. So I wonder if LassoCV () is broken, or do I need to do something else?

 In [2]: import numpy as np im In [3]: import sklearn.linear_model In [4]: from sklearn import linear_model In [5]: X = np.random.random((10,100)) In [6]: y = np.random.random((50, 100)) In [7]: linear_model.Lasso().fit(X,y) Out[7]: Lasso(alpha=1.0, copy_X=True, fit_intercept=True, max_iter=1000, normalize=False, positive=False, precompute='auto', tol=0.0001, warm_start=False) In [8]: linear_model.LassoCV().fit(X,y) --------------------------------------------------------------------------- ValueError Traceback (most recent call last) <ipython-input-8-9c8ad3459ac8> in <module>() ----> 1 linear_model.LassoCV().fit(X,y) /chimerahomes/wenhoujx/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/sklearn/linear_model/coordinate_descent.pyc in fit(self, X, y) 1006 if y.ndim > 1: 1007 raise ValueError("For multi-task outputs, use " -> 1008 "MultiTask%sCV" % (model_str)) 1009 else: 1010 if sparse.isspmatrix(X): ValueError: For multi-task outputs, use MultiTaskLassoCV In [9]: 

It seems that a couple of ElasticCV () and Elastic () have the same situation, the first () suggests using multitask-ElasticCV (), and the latter works fine for a 2d matrix.

+5
source share
1 answer

Unlike what is written in some dockers, regular lasso scores, such as the one you use, do not support several purposes.

The error message tells you to use MultiTaskLasso , which is a type of lasso group, which forces the same sparse support for each target. If this is what you need, continue to use it. If not, then at the moment there is no other useful way, in addition to sklearn.externals.joblib over targets that you can embarrass to parallelize with sklearn.externals.joblib .

(If you enjoy supporting multiple target server support for independent purposes, a port request to github would be greatly appreciated.)

+2
source

Source: https://habr.com/ru/post/1204991/


All Articles