📄 svm_vccore.m
字号:
% Learns classifier and classifies test set% using the perceptron learning algorithm% Works with 2 class labels, any number of features% when the class labels are -1 and 1.% Invoke using SVM_VC% % Inputs:% Usage% [trainError, testError, estTrainLabels, estTestLabels] = ...% SVM_VCcore(trainFeatures, trainLabels,algParam ,testFeatures, testLabels)% where%% Inputs:% trainFeatures - the training set vectors, one vector per column% trainLabels - the labels of the above% algParam - algorithm parameters:% kernel + kernelparameters% 'linear' None% 'poly' polynomial order% 'rbf' scale factor% Note: kernel 'rbffull' is not used% % testFeatures - test set, one column per vector% testLabels - labels for test set%% Outputs% trainError - the error rate on the training set (one entry per% class + total error)% testError - the error rate on the test set (one entry per class% + total error)% estTrainLabels - the labels produced by the algorithm for the% training samples% estTestLabels - the labels produced by the algorithm for the% test samplesfunction [trainError, testError, estTrainLabels, estTestLabels] = ... SVM_VCcore(trainFeatures, trainLabels,algParam,testFeatures, testLabels)comma_loc = findstr(algParam,',');kernel = algParam(3:comma_loc(1)-2);kernelpar = str2num(algParam(comma_loc(1)+1:length(algParam)-1));[Nclasses, classes] = find_classes([trainLabels(:);testLabels(:)]);if ( max(classes) == min(classes)) estTrainLabels = ones(size(trainLabels)) * max(classes); estTestLabels = ones(size(testLabels)) * max(classes);elseif (max(classes) ~= 1 | min(classes) ~= -1), if ( min(classes)==0) trainLabels(find(trainLabels==0))=-1; testLabels(find(testLabels==0))=-1; else fprintf('When invoking this classifier, use only labels -1 and 1\n'); return; endendtrainFeatures = trainFeatures'; % this is how the algorithms appears to work;[Nsam, Dim] = size(trainFeatures);net = construct_svm(Dim,kernel,kernelpar,100); % default valuenet = svmtrain(net,trainFeatures,trainLabels',[]);testFeatures = testFeatures';[estTrainLabels,foo] = svmfwd(net,trainFeatures);[estTestLabels,foo] = svmfwd(net,testFeatures);trainError = computeError( classes, trainLabels, estTrainLabels);testError = computeError( classes, testLabels, estTestLabels);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -