📄 ls_vc.m
字号:
% Learns classifier and classifies test set% using the least-squares algorithm%% If there are 2 classes, there is no problem (except that the labels are% converted to 0 and 1).% If there are more than 2 classes, pairwise classification is made,% followed by majority vote.%% Inputs:% Usage% [trainError, testError, estTrainLabels, estTestLabels] = ...% LVQ1_VC(trainFeatures, trainLabels,Nmu ,testFeatures, testLabels)% where%% Inputs:% trainFeatures - the training set vectors, one vector per column% trainLabels - the labels of the above% Nmu - Number of centroids% 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] = ... LS_VC(trainFeatures, trainLabels, weights, testFeatures, testLabels)[Nclasses, classes] = find_classes([trainLabels(:);testLabels(:)]);% Number of classes in labelshm = findobj('Tag', 'Messages'); fprintf('Least Squares Algorithm\n');if (isempty(hm)==0) s = sprintf('Least Squares Algorithm\n'); set(hm,'String',s); refresh; pause(.1);endif (Nclasses > 2) [trainError, testError] = classifierWrapper(trainFeatures, trainLabels, ... 'LS_VCcore', weights, testFeatures, testLabels);else if (max(classes) > 1 | min(classes) <0) ind0tr = find(trainLabels == min(classes)); ind0te = find(testLabels == min(classes)); ind1tr = find(trainLabels == max(classes)); ind1te = find(testLabels == max(classes)); trainLabels(ind0tr) = 0; trainLabels(ind1tr) = 1; testLabels(ind0te) = 0; testLabels(ind1te) = 1; end [trainError, testError] = LS_VCcore(trainFeatures, trainLabels, weights, testFeatures, testLabels);end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -