Closed Rockingsnow closed 5 years ago
@Rockingsnow I cannot replicate with current master branch:
alex@:mne-python(master)$ ipython
Python 2.7.12 |Anaconda custom (x86_64)| (default, Jul 2 2016, 17:43:17)
Type "copyright", "credits" or "license" for more information.
IPython 5.0.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: %run debug5
Module created for script run in IPython
Classification accuracy: 0.933333 / Chance level: 0.533333```
@agramfort Why can you run successfully? Is my development environment not configured right or what code is missing?
This is my version information: import sys print sys.version print sys.version_info 2.7.13 |Anaconda, Inc.| (default, Sep 19 2017, 08:25:59) [MSC v.1500 64 bit (AMD64)] sys.version_info(major=2, minor=7, micro=13, releaselevel='final', serial=0)
Should I update my python to version 2.7.12 or 3.0 ?
what MNE version are you using?
what does :
mne.sys_info()
gives you?
Recently I have updated my MNE version to the latest one —version 0.16.2 :
NAME mne - MNE software for MEG and EEG data analysis.
FILE c:\users\user\anaconda2\lib\site-packages\mne__init__.py
PACKAGE CONTENTS annotations baseline beamformer (package) bem channels (package) chpi commands (package) connectivity (package) coreg cov cuda data (package) datasets (package) decoding (package) defaults dipole epochs event evoked externals (package) filter fixes forward (package) gui (package) inverse_sparse (package) io (package) label minimum_norm (package) misc parallel preprocessing (package) proj realtime (package) report selection simulation (package) source_estimate source_space stats (package) surface tests (package) time_frequency (package) transforms utils viz (package)
DATA version = '0.16.2'
VERSION 0.16.2
you need to use the latest master version (unreleased)
See https://mne-tools.github.io/dev/advanced_setup.html#advanced-setup
use something like this:
pip install --upgrade --no-deps https://api.github.com/repos/mne-tools/mne-python/zipball/master
I don't know there is also a newer version of MNE! All right, I will try soon.
Also the output of:
>>> import mne
>>> mne.sys_info()
Would be helpful. This is what @agramfort was asking for. It looks like you pasted something different above.
After updating my MNE to the latest version——mne-0.17.dev0 : Platform: Windows-10-10.0.15063 Python: 2.7.13 |Anaconda, Inc.| (default, Sep 19 2017, 08:25:59) [MSC v.1500 64 bit (AMD64)] Executable: C:\Users\user\Anaconda2\pythonw.exe CPU: Intel64 Family 6 Model 63 Stepping 2, GenuineIntel: 28 cores Memory: 31.9 GB
mne: 0.17.dev0 numpy: 1.13.1 {lapack=mkl_rt, blas=mkl_rt} scipy: 0.19.1 matplotlib: 2.0.2 {backend=TkAgg}
sklearn: 0.19.0 nibabel: 2.2.1 mayavi: Not found cupy: Not found pandas: 0.20.3 dipy: Not found
The same error still occurred as follow:
File "C:\Users\user\Anaconda2\lib\site-packages\mne\utils.py", line 797, in verbose return function(*args, **kwargs)
File "C:\Users\user\Anaconda2\lib\site-packages\mne\io\meas_info.py", line 1783, in create_info ("list, tuple, or int"))
File "C:\Users\user\Anaconda2\lib\site-packages\mne\utils.py", line 2915, in _validate_type ', got %s instead.' % (type(item),))
TypeError: ('ch_names', ' must be an instance of ', 'list, tuple, or int', ", got <type 'long'> instead.")
can you open your meas_info.py file (in your mne install) and see if it works when you replace this line:
https://github.com/mne-tools/mne-python/blob/master/mne/io/meas_info.py#L1780
by
if isinstance(ch_names, integer_types):
making sure you import integer_types from six like this:
from ..externals.six import string_types, integer_types
This process is effective and my code have run successfully as well, I think that this problem may be caused by the incompatible of integral type between python 2.7 ( support int and long type) and the code of version 3.5(only support int type). your advice does solve my problem eventually,thanks!
great
@Rockingsnow do you want to give a try to contribute the fix to MNE with a pull request? or shall we do it?
I hope so, but I don't know the specific operation process or you can help me deal with it.
this should help https://mne-tools.github.io/dev/contributing.html?highlight=contributing
and more generally for learning github : https://help.github.com/articles/creating-a-pull-request-from-a-fork/
@Rockingsnow if you need help when attempting you swing by https://gitter.im/mne-tools/mne-python
I have the same issue. However, @agramfort 's fix
if isinstance(ch_names, integer_types):
doesn't solve the issue.
mne.sys_info():
Platform: Windows-7-6.1.7601-SP1 Python: 2.7.15 |Anaconda custom (64-bit)| (default, May 1 2018, 18:37:09) [MSC v.1500 64 bit (AMD64)] Executable: C:\Users\Public\Anaconda2\pythonw.exe CPU: Intel64 Family 6 Model 78 Stepping 3, GenuineIntel: 4 cores Memory: 7.9 GB
mne: 0.16.2 numpy: 1.12.1 {lapack=mkl_rt, blas=mkl_rt} scipy: 1.1.0 matplotlib: 2.1.0 {backend=Qt5Agg}
sklearn: 0.19.1 nibabel: 2.0.2 mayavi: Not found pycuda: Not found skcuda: Not found pandas: 0.23.1
When I run this...
import mne
from mne.decoding import CSP
import numpy as np
from numpy import random
import pandas as pd
import matplotlib.pyplot as plt
import os
from sklearn.model_selection import cross_val_score
from sklearn.model_selection import ShuffleSplit
from sklearn.pipeline import Pipeline
from sklearn.discriminant_analysis import LinearDiscriminantAnalysis
def train_test_split(data, test_ratio):
random.seed(42)
shuf_ind = random.permutation(len(data))
test_size = int(len(data) * test_ratio)
test_idx = shuf_ind[:test_size]
train_idx = shuf_ind[test_size:]
return train_idx, test_idx
##############
# setting-up #
##############
# get the data
os.chdir(r'C:\Users\John Doe\surfdrive\Alpha\data\ML_format\features')
all_trials_raw = mne.read_epochs('all_trials_raw-epo.fif', preload=False)
# get the labels
os.chdir(r'C:\Users\John Doe\surfdrive\Alpha\data\ML_format\labels')
labels = pd.read_csv('response.txt',
delim_whitespace=True,
header=None,
names=['subjectID', 'condition', 'ISI', 'response'])
#labels.info()
# split training and test set
train_idx, test_idx = train_test_split(all_trials_raw, 0.2)
xtrain = all_trials_raw[train_idx]
ytrain = labels.response.iloc[train_idx]
## first, to test CSP, filter data in alpha range (no filter bank yet)
#xtrain.load_data().filter(l_freq=8.0, h_freq=13.0)
## after filtering, discard everything but 1 sec pre-stimulus (i.e. dump the buffer zones that were only there to protect against filter artifacts)
#xtrain.load_data().crop(tmin=-1.0, tmax=0)
# now let's apply CSP to the data and plot the filters
csp = CSP()
csp.fit(xtrain.get_data(), ytrain)
... the following error occurs:
runfile('C:/Users/John Doe/surfdrive/Alpha/code/pre_processing/FBCSP.py', wdir='C:/Users/John Doe/surfdrive/Alpha/code/pre_processing') Reading all_trials_raw-epo.fif ... Found the data of interest: t = -3000.00 ... 2996.09 ms 0 CTF compensation matrices available 3520 matching events found Applying baseline correction (mode: mean) 3520 matching events found Applying baseline correction (mode: mean) Not setting metadata 0 projection items activated Loading data for 2816 events and 1536 original time points ... Traceback (most recent call last):
File "
File "C:\Users\Public\Anaconda2\lib\site-packages\spyder\utils\site\sitecustomize.py", line 705, in runfile execfile(filename, namespace)
File "C:\Users\Public\Anaconda2\lib\site-packages\spyder\utils\site\sitecustomize.py", line 87, in execfile exec(compile(scripttext, filename, 'exec'), glob, loc)
File "C:/Users/John Doe/surfdrive/Alpha/code/pre_processing/FBCSP.py", line 65, in
File "C:\Users\Public\Anaconda2\lib\site-packages\mne\decoding\csp.py", line 172, in fit class_, reg=self.reg, method_params=self.cov_method_params)
File "C:\Users\Public\Anaconda2\lib\site-packages\mne\cov.py", line 1586, in _regularized_covariance info = create_info(data.shape[-2], 1000., 'eeg') if info is None else info
File "
File "C:\Users\Public\Anaconda2\lib\site-packages\mne\utils.py", line 729, in verbose return function(*args, **kwargs)
File "C:\Users\Public\Anaconda2\lib\site-packages\mne\io\meas_info.py", line 1745, in create_info if not isinstance(ch_names, (list, tuple)):
TypeError: ch_names must be a list, tuple, or int
The integer_types
is probably not as robust as:
import operator
try: # integer
ch_names = [operator.index(ch_names)]
except TypeError:
pass
can you try that fix?
Also updating to latest mne
master you will get a more informative message saying what the errant type is
Still throws the same error when I
import operator
and insert
try: # integer
ch_names = [operator.index(ch_names)]
except TypeError:
pass
immediatly above https://github.com/mne-tools/mne-python/blob/master/mne/io/meas_info.py#L1780
@JohnDoenut can you tell us what is ch_names (type and value) before the try?
the data.shape[-2] argument taken by create_info in meas_info.py pertains to
xtrain.get_data()
xtrain.get_data().shape[-2]
gives 62L
What is type(np.long(10))
and type(operator.index(np.long(10)))
? I'm surprised that the operator.index
fix does not take care of this.
Actually instead could you try #5603 to see if it fixes your issue?
I applied the fix again, this time correctly as in https://github.com/mne-tools/mne-python/pull/5603. I didn't remove
if isinstance(ch_names, int):
before.
This solves the ch_names issue.
When I run the sample code in Python 2.7,the error happened as follow: