Undefined function 'mtimes' for input arguments of type 'nominal'.

3 visualizaciones (últimos 30 días)
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!!

Respuesta aceptada

Tom Lane
Tom Lane el 29 de Ag. de 2012
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 comentarios
Jan
Jan el 29 de Ag. de 2012
Editada: Walter Roberson el 29 de Ag. de 2012
@Yang: Because we neither know where and also not why the value is changed, we cannot know how to solve this either.
Tom Lane
Tom Lane el 29 de Ag. de 2012
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.

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by