⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ls_vccore.m

📁 最新的模式识别分类工具箱,希望对朋友们有用!
💻 M
字号:
% Learns classifier and classifies test set%  using the least-squares algorithm% 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(:)]); if (Nclasses > 2)  fprintf('The current version of the classifier deals with 2 classes only');  trainError = ones(size(classes));  testError  = ones(size(classes));  return;end[Dim, Nf]       = size(trainFeatures);Dim             = Dim + 1;trainFeatures(Dim,:) = ones(1,Nf);[Dim1,Nf1]      = size(testFeatures);testFeatures(Dim1+1,:) = ones(1,Nf1);%Weighted LS or not?switch length(weights),case Nf + 1,    %Ada boost form    weights = weights(1:Nf);case Nf,    %Do nothingotherwise    weights = ones(1, Nf);endmaxLabel = max(trainLabels);minLabel = min(trainLabels);if ( maxLabel ~= 1 | minLabel ~= 0)  else  train_one  = find(trainLabels == 1);  train_zero = find(trainLabels == 0);    %Preprocess the labels  mod_trainLabels = 2*trainLabels - 1;   w = inv((trainFeatures .* (ones(Dim,1)*weights)) * trainFeatures') * ...      (trainFeatures .* (ones(Dim,1)*weights)) * mod_trainLabels';     estTrainLabels = w'*trainFeatures;  estTrainLabels = estTrainLabels > 0;  trainError = computeError(classes, trainLabels, estTrainLabels);  estTestLabels = w'*testFeatures;  estTestLabels = estTestLabels > 0;  testError = computeError(classes, testLabels, estTestLabels);end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -