Repository navigation
Closed
Description
n,p = 2194, 12277
X = np.random.normal(0, 1, (n, p))
y = X[:,1] + X[:,2] + np.random.normal(0,1, n)
l1 = LassoLarsCV(n_jobs=1).fit(X,y)
print(l1.coef_)
l = LassoLarsCV(n_jobs=-1).fit(X,y)
print(l.coef_)
OUTPUT
>>>
>>>
[ 0. 0.91122441 0.88051206 ..., 0. 0. 0. ]
multiprocessing.pool.RemoteTraceback:
"""
Traceback (most recent call last):
File "/usr/local/lib/python3.4/dist-packages/sklearn/externals/joblib/parallel.py", line 94, in __call__
return self.func(*args, **kwargs)
File "/usr/local/lib/python3.4/dist-packages/sklearn/linear_model/least_angle.py", line 853, in _lars_path_residues
X_train -= X_mean
ValueError: output array is read-only
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3.4/multiprocessing/pool.py", line 119, in worker
result = (True, func(*args, **kwds))
File "/usr/local/lib/python3.4/dist-packages/sklearn/externals/joblib/parallel.py", line 104, in __call__
raise TransportableException(text, e_type)
sklearn.externals.joblib.my_exceptions.TransportableException: TransportableException
___________________________________________________________________________
ValueError Wed Apr 15 14:14:46 2015
PID: 4123 Python 3.4.0: /usr/bin/python3
...........................................................................
/usr/local/lib/python3.4/dist-packages/sklearn/linear_model/least_angle.py in _lars_path_residues(X_train=memmap([[ 1.00577915, -1.05126903, 1.30304231, ... -0.35100295,
-0.9267396 , 0.63928884]]), y_train=array([ 1.3232542 , 0.84262663, -2.62905025, ..., 1.62472897,
-1.45902494, -5.00504709]), X_test=array([[-0.31256648, -0.8413869 , 0.46347277, .... 1.21977537,
-1.12781956, -1.12695671]]), y_test=array([ -1.91413301e-02, -7.90822410e-01, -2.1...2352138e-01, -2.06750561e+00, -3.79778359e-01]), Gram='auto', copy=False, method='lasso', verbose=0, fit_intercept=True, normalize=True, max_iter=500, eps=2.2204460492503131e-16)
848 X_test = X_test.copy()
849 y_test = y_test.copy()
850
851 if fit_intercept:
852 X_mean = X_train.mean(axis=0)
--> 853 X_train -= X_mean
X_train = memmap([[ 1.00577915, -1.05126903, 1.30304231, ... -0.35100295,
-0.9267396 , 0.63928884]])
X_mean = memmap([-0.01531417, 0.02889734, -0.01592266, ..., 0.00315228,
-0.00060194, 0.01170645])
854 X_test -= X_mean
855 y_mean = y_train.mean(axis=0)
856 y_train = as_float_array(y_train, copy=False)
857 y_train -= y_mean
ValueError: output array is read-only
___________________________________________________________________________
"""
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/local/lib/python3.4/dist-packages/sklearn/externals/joblib/parallel.py", line 518, in retrieve
self._output.append(job.get())
File "/usr/lib/python3.4/multiprocessing/pool.py", line 599, in get
raise self._value
sklearn.externals.joblib.my_exceptions.TransportableException: TransportableException
___________________________________________________________________________
ValueError Wed Apr 15 14:14:46 2015
PID: 4123 Python 3.4.0: /usr/bin/python3
...........................................................................
/usr/local/lib/python3.4/dist-packages/sklearn/linear_model/least_angle.py in _lars_path_residues(X_train=memmap([[ 1.00577915, -1.05126903, 1.30304231, ... -0.35100295,
-0.9267396 , 0.63928884]]), y_train=array([ 1.3232542 , 0.84262663, -2.62905025, ..., 1.62472897,
-1.45902494, -5.00504709]), X_test=array([[-0.31256648, -0.8413869 , 0.46347277, .... 1.21977537,
-1.12781956, -1.12695671]]), y_test=array([ -1.91413301e-02, -7.90822410e-01, -2.1...2352138e-01, -2.06750561e+00, -3.79778359e-01]), Gram='auto', copy=False, method='lasso', verbose=0, fit_intercept=True, normalize=True, max_iter=500, eps=2.2204460492503131e-16)
848 X_test = X_test.copy()
849 y_test = y_test.copy()
850
851 if fit_intercept:
852 X_mean = X_train.mean(axis=0)
--> 853 X_train -= X_mean
X_train = memmap([[ 1.00577915, -1.05126903, 1.30304231, ... -0.35100295,
-0.9267396 , 0.63928884]])
X_mean = memmap([-0.01531417, 0.02889734, -0.01592266, ..., 0.00315228,
-0.00060194, 0.01170645])
854 X_test -= X_mean
855 y_mean = y_train.mean(axis=0)
856 y_train = as_float_array(y_train, copy=False)
857 y_train -= y_mean
ValueError: output array is read-only
___________________________________________________________________________
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/donbeo/Desktop/prova.py", line 31, in <module>
l = LassoLarsCV(n_jobs=-1).fit(X,y)
File "/usr/local/lib/python3.4/dist-packages/sklearn/linear_model/least_angle.py", line 999, in fit
for train, test in cv)
File "/usr/local/lib/python3.4/dist-packages/sklearn/externals/joblib/parallel.py", line 666, in __call__
self.retrieve()
File "/usr/local/lib/python3.4/dist-packages/sklearn/externals/joblib/parallel.py", line 549, in retrieve
raise exception_type(report)
sklearn.externals.joblib.my_exceptions.JoblibValueError: JoblibValueError
___________________________________________________________________________
Multiprocessing exception:
...........................................................................
/home/donbeo/Desktop/<stdin> in <module>()
----> 1
2
3
4
5
6
7
8
9
10
...........................................................................
/home/donbeo/Desktop/prova.py in <module>()
26 y = X[:,1] + X[:,2] + np.random.normal(0,1, n)
27
28
29 l1 = LassoLarsCV(n_jobs=1).fit(X,y)
30 print(l1.coef_)
---> 31 l = LassoLarsCV(n_jobs=-1).fit(X,y)
32 print(l.coef_)
33
34
35
...........................................................................
/usr/local/lib/python3.4/dist-packages/sklearn/linear_model/least_angle.py in fit(self=LassoLarsCV(copy_X=True, cv=None, eps=2.22044604...normalize=True, precompute='auto', verbose=False), X=array([[-0.31256648, -0.8413869 , 0.46347277, .... -0.35100295,
-0.9267396 , 0.63928884]]), y=array([-0.01914133, -0.79082241, -2.15777265, ..., 1.62472897,
-1.45902494, -5.00504709]))
994 delayed(_lars_path_residues)(
995 X[train], y[train], X[test], y[test], Gram=Gram, copy=False,
996 method=self.method, verbose=max(0, self.verbose - 1),
997 normalize=self.normalize, fit_intercept=self.fit_intercept,
998 max_iter=self.max_iter, eps=self.eps)
--> 999 for train, test in cv)
cv = sklearn.cross_validation.KFold(n=2194, n_folds=3, shuffle=False, random_state=None)
1000 all_alphas = np.concatenate(list(zip(*cv_paths))[0])
1001 # Unique also sorts
1002 all_alphas = np.unique(all_alphas)
1003 # Take at most max_n_alphas values
...........................................................................
/usr/local/lib/python3.4/dist-packages/sklearn/externals/joblib/parallel.py in __call__(self=Parallel(n_jobs=-1), iterable=<generator object <genexpr>>)
661 if pre_dispatch == "all" or n_jobs == 1:
662 # The iterable was consumed all at once by the above for loop.
663 # No need to wait for async callbacks to trigger to
664 # consumption.
665 self._iterating = False
--> 666 self.retrieve()
self.retrieve = <bound method Parallel.retrieve of Parallel(n_jobs=-1)>
667 # Make sure that we get a last message telling us we are done
668 elapsed_time = time.time() - self._start_time
669 self._print('Done %3i out of %3i | elapsed: %s finished',
670 (len(self._output),
---------------------------------------------------------------------------
Sub-process traceback:
---------------------------------------------------------------------------
ValueError Wed Apr 15 14:14:46 2015
PID: 4123 Python 3.4.0: /usr/bin/python3
...........................................................................
/usr/local/lib/python3.4/dist-packages/sklearn/linear_model/least_angle.py in _lars_path_residues(X_train=memmap([[ 1.00577915, -1.05126903, 1.30304231, ... -0.35100295,
-0.9267396 , 0.63928884]]), y_train=array([ 1.3232542 , 0.84262663, -2.62905025, ..., 1.62472897,
-1.45902494, -5.00504709]), X_test=array([[-0.31256648, -0.8413869 , 0.46347277, .... 1.21977537,
-1.12781956, -1.12695671]]), y_test=array([ -1.91413301e-02, -7.90822410e-01, -2.1...2352138e-01, -2.06750561e+00, -3.79778359e-01]), Gram='auto', copy=False, method='lasso', verbose=0, fit_intercept=True, normalize=True, max_iter=500, eps=2.2204460492503131e-16)
848 X_test = X_test.copy()
849 y_test = y_test.copy()
850
851 if fit_intercept:
852 X_mean = X_train.mean(axis=0)
--> 853 X_train -= X_mean
X_train = memmap([[ 1.00577915, -1.05126903, 1.30304231, ... -0.35100295,
-0.9267396 , 0.63928884]])
X_mean = memmap([-0.01531417, 0.02889734, -0.01592266, ..., 0.00315228,
-0.00060194, 0.01170645])
854 X_test -= X_mean
855 y_mean = y_train.mean(axis=0)
856 y_train = as_float_array(y_train, copy=False)
857 y_train -= y_mean
ValueError: output array is read-only
___________________________________________________________________________
>>> >>>
Activity
agramfort commentedon Apr 15, 2015
DonBeo commentedon Apr 15, 2015
I am having this problem on Ubuntu 14.04 running the 0.17dev version. It
was working fine with 0.16
On Wed, Apr 15, 2015, 14:36 Alexandre Gramfort [email protected]
wrote:
lesteve commentedon Apr 15, 2015
I can reproduce it (Ubuntu 14.04 too) but it doesn't seem to be related to 0.17dev0. I get the same error with scikit-learn 0.15.2 and 0.16.0.
amueller commentedon Apr 16, 2015
ping @ogrisel @GaelVaroquaux, our parallelization experts?
koefoed commentedon Apr 22, 2015
I can reproduce DonBeo's error with sklearn 0.16.1.
Also, I have experienced a similar issue with
GridSearchCVand Pandas data frames (see below).Oddly, the behavior seems to depend on the shape of the data set. A small data set runs fine whereas a larger data set does not.
A suggested workaround is to use
gs2.fit(X.values, y.values)below.Results in (a bunch of
DataConversionWarning: A column-vector y was passed when a 1d array was expectedhas been omitted):The same issue has been reported by other people as well:
agramfort commentedon Apr 23, 2015
koefoed commentedon Apr 25, 2015
@agramfort, I do not quite understand what you mean by
Also, it does not work when passing (large) pandas data frames.
Maybe I am not understanding what you mean.
agramfort commentedon Apr 26, 2015
amueller commentedon Apr 27, 2015
I think the problem is in the slicing of the data, which doesn't call
check_arrayas we don't want to convert data to an array in the cross-validation / grid-search part.If the data is a large list of strings, that would be pretty bad. Also, someone might want to use a pd dataframe as input in their estimator, and converting to numpy array early would be bad for that.
So safe_indexing seems to break for pandas dataframes sometimes...
So the problem is with
return X.iloc[indices]amueller commentedon May 1, 2015
I opened an issue at pandas: pandas-dev/pandas#10043 I don't understand the behavior, maybe using
ilocis not the right way to slice.amueller commentedon May 1, 2015
@ogrisel @GaelVaroquaux could either of you explain why X is not writable? This is multi-processing, and X is copied, right?
amueller commentedon May 1, 2015
This is actually a Cython issue, there are no read-only cython buffers, so input on why there is a read-only flag would be great.
ogrisel commentedon May 5, 2015
By default the automated memory mapping feature of joblib is converting all big arrays into read-only
np.memmapinstances in the multiprocessing workers.There exists two additional modes for memory mapping:
Ideally we would therefore use copy-on-write as a reasonable default. Unfortunately the support for the copy-on-write mode under Windows is half broken and tends to crash on large data: see joblib/joblib#150.
In this case we should separate the issue with
LassoLarsCVfrom the one related to slicing a pandas data frame backed by a memory mapped array in read-only mode. For the original problem withLassoLarsCVI think it's a design problem in this class (or its internals): no estimator should try to edit the input data by default, unless the user explicitly passcopy=False. I will try to have deeper look.For the problem happening when using grid search on a large data frame, I think it better to track the discussion in pandas-dev/pandas#10043 as I think this is might be a problem with the way
pandas.DataFrame.ilocis currently implemented.Side note: joblib uses memory mapping to share arrays between Python processes (forked by multiprocessing when doing a
GridSearchCVorLassoLarsCVwithn_jobs != 1). memory mapping is not used when using joblib in threading mode as it the case inRandomForestClassifierwithn_jobs != 1. Threading used shared memory by default but unfortunately the threading mode can only be used efficiently by Cython code that releeases the GIL, this is why we cannot use it for general utilities likeGridSearchCV.15 remaining items
amueller commentedon May 6, 2015
I can reproduce the lassoCV failure with the code that is provided, but not "manually":
runs through just fine. I don't understand.
ogrisel commentedon May 7, 2015
Indeed, it's the inner, CV'ed data that is read-only when using LassoLarsCV on a large input (more than 100MB). I have a fix but it's hard to comme up with a non-regression test that executes quickly...
ogrisel commentedon May 7, 2015
I can write a unittest on
_lars_path_residuesbut this does not feel satisfactory.ogrisel commentedon May 7, 2015
FYI here is the fix I have in mind:
ogrisel commentedon May 7, 2015
Let me do a fix with a unittest on
_lars_path_residuesonly.FIX scikit-learn#4597: LassoLarsCV on with readonly folds
amueller commentedon May 7, 2015
Do all four arrays need to be writable?
mozark24 commentedon May 11, 2018
I'm facing this issue. n_jobs cannot be set > 1.
jnothman commentedon May 13, 2018
This is very likely fixed in master if the most recent version of cython is used to compile it.
g1t-h1j4ck3r commentedon Oct 30, 2018
I have the same problem with OneClassSVM using GridSearchCV with n_jobs > 1.
Since the training/cv is very slow already, it is not really practicable to use just one job.
Avoid ValueError in parallel computing of large arrays
Avoid ValueError in parallel computing of large arrays
Allowing optional list of Parallel keyworded parameters
Allowing optional list of Parallel keyworded parameters