ValueError: data copying was not requested by copy=None but it was required to get to double floating point precision cross_val_score

Hi, I know that there already is a discussion about this error, but mine doesn’t come changing data dtype.

I’m trying to make this simple pipeline and evaluate it’s accuracy, but for some reason I keep having this error ValueError: data copying was not requested by copy=None but it was required to get to double floating point precision cross_val_score on the cross_val_score line.

The weird thing is that I first encountered this error when trying to setup the pipeline with sklearn method ‘make_pipeline’. So I switched to this basic Pipeline(steps=…) call, and the first time I ran this code it actually worked. And when running it again it wouldn’t work.
I’m kinda lost here.

Here is my code :

epochs_data = epochs.get_data()
scores = []
cv = ShuffleSplit(10, test_size=.3, random_state=99)

reg = LogisticRegression()
csp = CSP(n_components=10, reg=None, log=True, norm_trace=False)

clf = Pipeline(steps=[('CSP', csp), ('LogisticRegression', reg)])
scores = cross_val_score(clf, epochs_data, labels, cv=cv, n_jobs=-1)

I got the epochs object with :

# Files corresponds the raw data (concatenated)
events, event_id = events_from_annotations(files, event_id=event_mapping)
epochs = Epochs(files, events, event_id, tmin, tmax, proj=True,
                picks=picks, baseline=None, preload=True)

what sklearn and mne versions are you using?


I have mne 1.3.1 and scikit-learn 1.2.2

Hi! I am facing the same problem. I didn’t convert my data type. I have it in a matlab file, read it, filter it and then when train the CSP class I got this error. Important to mention is that my data type are arrays of float 64, and that I am just running an exciting code that used to run in MNE 0.19.0

Hello! Seems that the problem appears when an n_jobs other than None or 1 is supplied to the cross_val_score. Fast (or slow actually) solution is to not to try speeding-up the function. Also, it seems that the problem arises when a multiple (>2) algorithms are used in the Pipeline. Reproduced with:

  • joblib: 1.3.2
  • scikit-learn: 1.3.1
  • mne: 1.5.1

Hi, I’ve faced same problem today.
The CSP works well on samples of MNE but not OK on my data. My solution is using numpy.astype(np.float64) to convert data explicitly to float64. After that I faced the following problem, and solved it by np.round() to manually decrease precision of my data to, say 1e-9 V.

LinAlgError: The leading minor of order 54 of B is not positive definite. The factorization of B could not be completed and no eigenvalues or eigenvectors were computed.

Platform Windows-10-10.0.19045-SP0
Python 3.11.6 | packaged by conda-forge | (main, Oct 3 2023, 10:29:11) [MSC v.1935 64 bit (AMD64)]
Executable E:\conda_env\mne\pythonw.exe
CPU Intel64 Family 6 Model 158 Stepping 10, GenuineIntel (12 cores)
Memory 31.8 GB

├☑ mne 1.5.1
├☑ numpy 1.25.2 (MKL 2023.1-Product with 6 threads)
├☑ scipy 1.11.3
├☑ matplotlib 3.7.3 (backend=Qt5Agg)
├☑ pooch 1.7.0
└☑ jinja2 3.1.2