[pymvpa] TypeError: unhashable type: 'numpy.ndarray'

Yaroslav Halchenko debian at onerussian.com
Tue Aug 20 14:53:07 UTC 2013


just make your targets 1D vector, e.g. via

regressor = np.squeeze(regressor)

or 

regressor = regressor[:, 0]

Cheers,

On Tue, 20 Aug 2013, Dmitry Smirnov wrote:

>    Hi!

>    I'm trying to run some simple classification to get used to PyMVPA.
>    Specifically, I'm trying to classify 4 types of stimuli presented using
>    mask of 4501 voxels.
>    Here is the error and code. I'm new to python, so not much of experience
>    in figuring out error messages. Thanks in advance for all the suggestions!
>    ERROR:
>    Traceback (most recent call last):
>    � File "<stdin>", line 1, in <module>
>    � File "/scratch/braindata/DSmirnov/PyMVPA/mvpa2/base/learner.py", line
>    239, in __call__
>    ��� return super(Learner, self).__call__(ds)
>    � File "/scratch/braindata/DSmirnov/PyMVPA/mvpa2/base/node.py", line 84,
>    in __call__
>    ��� result = self._call(ds)
>    � File "/scratch/braindata/DSmirnov/PyMVPA/mvpa2/measures/base.py", line
>    472, in _call
>    ��� return super(CrossValidation, self)._call(ds)
>    � File "/scratch/braindata/DSmirnov/PyMVPA/mvpa2/measures/base.py", line
>    301, in _call
>    ��� result = node(sds)
>    � File "/scratch/braindata/DSmirnov/PyMVPA/mvpa2/base/learner.py", line
>    239, in __call__
>    ��� return super(Learner, self).__call__(ds)
>    � File "/scratch/braindata/DSmirnov/PyMVPA/mvpa2/base/node.py", line 84,
>    in __call__
>    ��� result = self._call(ds)
>    � File "/scratch/braindata/DSmirnov/PyMVPA/mvpa2/measures/base.py", line
>    583, in _call
>    ��� res = measure(dstest)
>    � File "/scratch/braindata/DSmirnov/PyMVPA/mvpa2/base/learner.py", line
>    239, in __call__
>    ��� return super(Learner, self).__call__(ds)
>    � File "/scratch/braindata/DSmirnov/PyMVPA/mvpa2/base/node.py", line 84,
>    in __call__
>    ��� result = self._call(ds)
>    � File "/scratch/braindata/DSmirnov/PyMVPA/mvpa2/clfs/base.py", line 438,
>    in _call
>    ��� pred = self.predict(ds)
>    � File "/scratch/braindata/DSmirnov/PyMVPA/mvpa2/clfs/base.py", line 48,
>    in wrap_samples
>    ��� return fx(obj, data, *args, **kwargs)
>    � File "/scratch/braindata/DSmirnov/PyMVPA/mvpa2/clfs/base.py", line 409,
>    in predict
>    ��� result = self._predict(dataset)
>    � File "/scratch/braindata/DSmirnov/PyMVPA/mvpa2/base/types.py", line 35,
>    in extract_samples
>    ��� return fx(obj, data.samples)
>    � File "/scratch/braindata/DSmirnov/PyMVPA/mvpa2/clfs/knn.py", line 191,
>    in _predict
>    ��� votes[labels[nn]] += 1
>    TypeError: unhashable type: 'numpy.ndarray'

>    CODE:

>    from mvpa2.suite import *

>    from scipy import *

>    # samples: 1730x4501 matrix, rows=timepoints, columns=voxels
>    # regressor: 1730x1 vector, rows=labels of stimuli
>    # chunks: 1730x1 vector, rows=labels of independent runs (5 of them)

>    ds = dataset_wizard(samples, targets = regressor, chunks = selector)

>    clf = kNN(k=1, dfx=one_minus_correlation, voting='majority')

>    cvte = CrossValidation(clf, NFoldPartitioner())

>    cv_results = cvte(ds)

>    BR, Dima
-- 
Yaroslav O. Halchenko, Ph.D.
http://neuro.debian.net http://www.pymvpa.org http://www.fail2ban.org
Senior Research Associate,     Psychological and Brain Sciences Dept.
Dartmouth College, 419 Moore Hall, Hinman Box 6207, Hanover, NH 03755
Phone: +1 (603) 646-9834                       Fax: +1 (603) 646-1419
WWW:   http://www.linkedin.com/in/yarik        



More information about the Pkg-ExpPsy-PyMVPA mailing list