我想将SVMStruct = svmtrain(Training,Group)
用于两个类( Noraml和Abnormal )图像分类目的,并且Training矩阵的大小为1*40 cells
,每个单元格为{ {1}}所以我想将这个Training矩阵提供给75 rows * 10 columns
函数,但是在调用svmtrain
函数后我得到了这个错误:
使用svmtrain时出错(第241行) 培训必须是数字矩阵
任何人都可以指导如何更正此错误,因为我真的陷入了这个错误,谢谢。
以下是我尝试的代码行:
svmtrain
答案 0 :(得分:0)
这是为SVM编写的旧代码可能会帮助您
%# split training/testing sets
[trainIdx testIdx] = crossvalind('HoldOut', lbls, 1/2); % split the train and test labels 50%-50%
pairwise = nchoosek(1:size(gn, 1), 2); %# 1-vs-1 pairwise models
svmModel = cell(size(pairwise, 1), 1); %# store binary-classifers
predTest = zeros(sum(testIdx), numel(svmModel)); %# store binary predictions
%# classify using one-against-one approach, SVM with 3rd degree poly kernel
for k=1:numel(svmModel)
%# get only training instances belonging to this pair
idx = trainIdx & any( bsxfun(@eq, g, pairwise(k,:)) , 2 );
%# train
% svmModel{k} = svmtrain(dataset(idx,:), g(idx), ...
% 'BoxConstraint',2e-1, 'Kernel_Function','polynomial', 'Polyorder',3);
svmModel{k} = svmtrain(dataset(idx,:), g(idx), ...
'BoxConstraint', Inf, 'Kernel_Function', 'rbf', 'rbf_sigma', 14.51);
%# test
predTest(:,k) = svmclassify(svmModel{k}, dataset(testIdx,:)); % matlab native svm function
end
pred = mode(predTest, 2); %# voting: clasify as the class receiving most votes
%# performance
cmat = confusionmat(g(testIdx), pred); %# g(testIdx) == targets, pred == outputs
final_acc = 100*sum(diag(cmat))./sum(cmat(:));
fprintf('SVM (1-against-1):\naccuracy = %.2f%%\n', final_acc);
fprintf('Confusion Matrix:\n'), disp(cmat)
% assignin('base', 'cmatrix', cmat);
这是一个基于内容的图像检索项目,您可以搜索它,并会发现许多代码链接就像这个URL
http://www.mathworks.com/matlabcentral/fileexchange/42008-content-based-image-retrieval