[pymvpa] Error when using pearsonr with ridgeregression
Thomas Nickson
thomas.nickson at gmail.com
Thu Jan 15 11:30:06 UTC 2015
Hello,
I'm trying to use pearsonr to crossvalidate a ridge regression on some
structural data.
My code is:
#define the classifier
from mvpa2.clfs.gnb import GNB
from mvpa2.clfs.svm import LinearCSVMC, RbfCSVMC, RbfNuSVMC, LinearNuSVMC
from mvpa2.clfs.meta import FeatureSelectionClassifier
from mvpa2.clfs.warehouse import SensitivityBasedFeatureSelection,
FractionTailSelector, OneWayAnova
from mvpa2.clfs.ridge import RidgeReg
clf = RidgeReg()#LinearCSVMC()
#If some sort of feature selection is required use this to get a certain
percentage of the tail of an anova
"""
CLF = LinearCSVMC()
clf = FeatureSelectionClassifier(
CLF,
SensitivityBasedFeatureSelection(
OneWayAnova(),
FractionTailSelector(0.05, mode='select', tail='upper'))
)
"""
#Create a partitioner that generates equal sized testing and training sets
that are balanced
from mvpa2.generators.partition import HalfPartitioner
from mvpa2.generators.resampling import Balancer
from mvpa2.generators.base import Sifter
from mvpa2.base.node import ChainNode
metaPartitioner = HalfPartitioner()#NFoldPartitioner(cvtype=2)
partitioner = ChainNode([metaPartitioner,
Sifter([('partitions', 2),
('targets', [1, 2])]),
Balancer(attr='targets',
count=1, # can set > 1 if you dont have
"enough"
limit='partitions',
apply_selection=True
)],
space='partitions')
#Train the classifier
from mvpa2.generators.partition import NFoldPartitioner, HalfPartitioner
from mvpa2.measures.base import CrossValidation
from mvpa2.misc.errorfx import mean_match_accuracy, corr_error,
corr_error_prob, pearsonr
from mvpa2.mappers.fx import mean_sample
#use correlation error when using ridge regression
cv = CrossValidation(clf, partitioner, postproc=mean_sample(),
errorfx=pearsonr, enable_ca=['stats'])
the error is:
---------------------------------------------------------------------------ValueError
Traceback (most recent call
last)<ipython-input-22-0cdf8de46914> in <module>() 3 for dataset
in datasets: 4 print "Partition: " + dataset[0]----> 5
cv_results = cv(dataset[1]).samples 6 print cv_results 7
resTup = (dataset[0],cv_results)
/home/orkney_01/tnickson/Programming/pyVirtualEnv/lib/python2.6/site-packages/mvpa2/base/learner.pyc
in __call__(self, ds) 257 "used
and auto training is disabled." 258
% str(self))--> 259 return super(Learner,
self).__call__(ds) 260 261
/home/orkney_01/tnickson/Programming/pyVirtualEnv/lib/python2.6/site-packages/mvpa2/base/node.pyc
in __call__(self, ds) 119 120 self._precall(ds)--> 121
result = self._call(ds) 122 result =
self._postcall(ds, result) 123
/home/orkney_01/tnickson/Programming/pyVirtualEnv/lib/python2.6/site-packages/mvpa2/measures/base.pyc
in _call(self, ds) 495 # always untrain to wipe out
previous stats 496 self.untrain()--> 497 return
super(CrossValidation, self)._call(ds) 498 499
/home/orkney_01/tnickson/Programming/pyVirtualEnv/lib/python2.6/site-packages/mvpa2/measures/base.pyc
in _call(self, ds) 324 ca.datasets.append(sds)
325 # run the beast--> 326 result = node(sds)
327 # callback 328 if not self._callback
is None:
/home/orkney_01/tnickson/Programming/pyVirtualEnv/lib/python2.6/site-packages/mvpa2/base/learner.pyc
in __call__(self, ds) 257 "used
and auto training is disabled." 258
% str(self))--> 259 return super(Learner,
self).__call__(ds) 260 261
/home/orkney_01/tnickson/Programming/pyVirtualEnv/lib/python2.6/site-packages/mvpa2/base/node.pyc
in __call__(self, ds) 120 self._precall(ds) 121
result = self._call(ds)--> 122 result = self._postcall(ds,
result) 123 124 self.ca.calling_time = time.time() - t0
# set the calling_time
/home/orkney_01/tnickson/Programming/pyVirtualEnv/lib/python2.6/site-packages/mvpa2/measures/base.pyc
in _postcall(self, dataset, result) 124 if self.__null_dist
is None: 125 # do base-class postcall and be done-->
126 result = super(Measure, self)._postcall(dataset,
result) 127 else: 128 # don't do a full
base-class postcall, only do the
/home/orkney_01/tnickson/Programming/pyVirtualEnv/lib/python2.6/site-packages/mvpa2/base/node.pyc
in _postcall(self, ds, result) 164 """ 165
result = self._pass_attr(ds, result)--> 166 result =
self._apply_postproc(ds, result) 167 return result 168
/home/orkney_01/tnickson/Programming/pyVirtualEnv/lib/python2.6/site-packages/mvpa2/base/node.pyc
in _apply_postproc(self, ds, result) 238
"Applying post-processing node %s", (self.__postproc,)) 239
self.ca.raw_results = result--> 240 result =
self.__postproc(result) 241 return result 242
/home/orkney_01/tnickson/Programming/pyVirtualEnv/lib/python2.6/site-packages/mvpa2/base/node.pyc
in __call__(self, ds) 119 120 self._precall(ds)--> 121
result = self._call(ds) 122 result =
self._postcall(ds, result) 123
/home/orkney_01/tnickson/Programming/pyVirtualEnv/lib/python2.6/site-packages/mvpa2/mappers/fx.pyc
in _call(self, ds) 582 if np.isscalar(err): 583
err = np.array(err, ndmin=2)--> 584 return Dataset(err)
/home/orkney_01/tnickson/Programming/pyVirtualEnv/lib/python2.6/site-packages/mvpa2/base/dataset.pyc
in __init__(self, samples, sa, fa, a) 213 if not
hasattr(samples, 'dtype'): 214 raise ValueError(--> 215
"AttrDataset only supports dtypes as samples that have
a " 216 "`dtype` attribute that behaves similar to
the one of an " 217 "array-like.")
ValueError: AttrDataset only supports dtypes as samples that have a
`dtype` attribute that behaves similar to the one of an array-like.
Anybody know what this error is?
Thanks,
Tom
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.alioth.debian.org/pipermail/pkg-exppsy-pymvpa/attachments/20150115/10d9ea57/attachment.html>
More information about the Pkg-ExpPsy-PyMVPA
mailing list