Undefined function 'mtimes' for input arguments of type 'nominal'.
조회 수: 3 (최근 30일)
이전 댓글 표시
Dear all,
I want to use cross-validation function crossval to find some parameters of my SVM function. I follow the help document to have this .m file:
load UCI_abalone; %2088
data = [train_data;test_data];
label = [train_labels;test_labels];
data_size = size(data,1);
c = cvpartition(data_size,'kfold',10);
minfn = @(z)crossval('mcr',data,label,'Predfun', ...
@(xtrain,ytrain,xtest)crossfun(xtrain,ytrain,...
xtest,exp(z)),'partition',c);
opts = optimset('TolX',5e-4,'TolFun',5e-4);
[searchmin fval] = fminsearch(minfn,randn(1,1),opts)
the corresponding function is:
function [ ytest ] = crossfun(x,y,xtest,lambda)
p = size(x,2);
N = size(x,1);
w = zeros(p,1);
for i = 1:N
yita = 1 / sqrt(i);
if 1 - y(i) * x(i,:) * w > 0
w = w + y(i) * yita * x(i,:)';
end
if w' * w > 1 / lambda
w = w / sqrt(w' * w) / lambda;
end
end
ytest = xtest * w;
end
And when I run it, the error shows like this:
>> cv_test
Error using crossval>evalFun (line 465)
The function '@(xtrain,ytrain,xtest)crossfun(xtrain,ytrain,xtest,exp(z))' generated the following error:
Undefined function 'mtimes' for input arguments of type 'nominal'.
Error in crossval>getLossVal (line 502)
funResult = evalFun(funorStr,arg(1:end-1));
Error in crossval (line 401)
[funResult,outarg] = getLossVal(i, nData, cvp, data, predfun);
Error in
@(z)crossval('mcr',data,label,'Predfun',@(xtrain,ytrain,xtest)crossfun(xtrain,ytrain,xtest,exp(z)),'partition',c)
Error in fminsearch (line 191)
fv(:,1) = funfcn(x,varargin{:});
Error in cv_test (line 12)
[searchmin fval] = fminsearch(minfn,randn(1,1),opts)
Is there anyone can help me??? Thanks!!
댓글 수: 0
채택된 답변
Tom Lane
2012년 8월 29일
Try putting a break in the crossfun function and using "whos" to see what the y value is. If it's a nominal variable, then it looks like the problem is that you are trying to multiply it by a row of the x matrix.
I'm not exactly sure what you are trying to do. Could it be that you want the "label" variable to take on values +1 for one class and -1 for the other?
댓글 수: 4
Jan
2012년 8월 29일
편집: Walter Roberson
2012년 8월 29일
@Yang: Because we neither know where and also not why the value is changed, we cannot know how to solve this either.
Tom Lane
2012년 8월 29일
I also don't know where it changed. I can imagine some Statistics Toolbox code may operate on nominal values internally, but I would not expect that to affect you. A possibility is to write your crossfun function to deal with nominals. For instance, double(y(i)) will give 1 for y's first category, 2 for y's second category, and so on.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!