def __new__(self, time, y, x, clf='lda', cvtype=None, clfArg={},
cvArg={}):
self.y = np.ravel(y)
self.time = time
# Define clf if it's not defined :
if isinstance(clf, (int, str)):
clf = defClf(y, clf=clf, **clfArg)
self.clf = clf
# Define cv if it's not defined :
if isinstance(cvtype, str) and (cvtype is not None):
cvtype = defCv(y, cvtype=cvtype, rep=1, **cvArg)
self.cv = cvtype
if isinstance(cvtype, list):
cvtype = cvtype[0]
# Check the size of x:
x = np.atleast_3d(x)
npts, ntrials = len(time), len(y)
if x.shape[0] is not npts:
raise ValueError('First dimension of x must be '+str(npts))
if x.shape[1] is not ntrials:
raise ValueError('Second dimension of x must be '+str(ntrials))
da = np.zeros([npts, npts])
# Training dimension
for k in range(npts):
xx = x[k, ...]
# Testing dimension
for i in range(npts):
xy = x[i, ...]
# If cv is defined, do a cv on the diagonal
if (k == i) and (cvtype is not None):
da[i, k] = _cvscore(xx, y, clf, self.cv.cvr[0])[0]/100
# If cv is not defined, let the diagonal at zero
elif (k == i) and (cvtype is None):
pass
else:
da[i, k] = accuracy_score(y, clf.fit(xx, y).predict(xy))
return 100*da
评论列表
文章目录