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

3 ビュー (過去 30 日間)
Yang
Yang 2012 年 8 月 28 日
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!!

採用された回答

Tom Lane
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
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
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 件)

Community Treasure Hunt

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

Start Hunting!

Translated by