【发布时间】:2015-10-19 17:23:39
【问题描述】:
我正在尝试自定义“Efficient multiclass weighted majority voting implementation in MATLAB”中给出的代码以用于 4 个分类器,而选项保持 3 个不变。 bsxfun 返回错误:两个输入数组的非单一维度必须相互匹配。在这种情况下如何匹配输入的维度。这段代码如何与 4 个分类器和 3 个选项一起使用?任何想法,请帮助。 下面显示了我尝试自定义它的方式。
knn_weight = Accuracy_knn_datasets_overall; % average classification accuracy on the 5 fixed folds
nearest_centroid_weight = Accuracy_centroid_datasets_overall; % average classification accuracy on the 5 fixed folds
bayes_weight = Accuracy_bayes_datasets_overall; % average classification accuracy on the 5 fixed folds
nn_weight = mean([89.5,89.5,94.4,92.3,89.5]); % average of the classification accuracy of the testing sets for 5 iterations
% [knn,nearest_centroid,bayes,nn]; order of the base classifiers
w = [knn_weight nearest_centroid_weight bayes_weight nn_weight]; % weights of the classifiers based on their individual performance.
%% Merging the outputs of the base classifiers to yield a single output
knn_output_3 = knnPredicted_vehicleclass_dataset_3;
nearest_centroid_output_3 = centroidPredicted_vehicleclass_dataset_3;
nn_output_2 = nnPredicted_vehicleclass_dataset_2;
votes = [knn_output_3 nearest_centroid_output_3 bayes_output_3 nn_output_2]; % base classifiers predictions
output = votes;
expression = 'smallvehicle';
replace = 'S';
A = regexprep(output,expression,replace);
output = A;
expression = 'mediumvehicle';
replace = 'M';
A = regexprep(output,expression,replace);
output = A;
expression = 'largevehicle';
replace = 'L';
A = regexprep(output,expression,replace);
B = A(:,1); % outputs of knn
C = A(:,2); % outputs of nearest centroid
D = A(:,3); % outputs of bayes
E = A(:,4) % outputs of nn
A = char(strcat(B,C,D,E));
votes = A;
Classlabels = ['S', 'M', 'L']';
%'//Make a cube of the Classlabels that is number of Classlabels by m by n
OPTIONS = repmat(Classlabels, [1, size(w, 2), size(votes, 1)]);
%//Compare the votes (streched to make surface) against a uniform surface of each option
B = bsxfun(@eq, permute(votes, [3 2 1]) ,OPTIONS);
%//Find a weighted sum
W = squeeze(sum(bsxfun(@times, repmat(w, size(Classlabels, 1), 1), B), 2))';
%'//Find the Classlabels with the highest weighted sum
[xx, i] = max(W, [], 2);
output = cellstr(Classlabels(i));
output = output;
expression = 'S';
replace = 'smallvehicle';
A = regexprep(output,expression,replace);
output = A;
expression = 'L';
replace = 'largevehicle';
A = regexprep(output,expression,replace);
output = A;
expression = 'M';
replace = 'mediumvehicle';
Ensemble_output_3 = regexprep(output,expression,replace); % predicted class labels by the Ensemble classifier
Confusionmatrix_dataset_3 = confusionmat(YSML_3,Ensemble_output_3)
Ensmble_Accuracy_dataset_3 = (sum(diag(Confusionmatrix_dataset_3))/sum(sum(Confusionmatrix_dataset_3)))*100
返回的错误是:Error using bsxfun 两个输入数组的非单一维度必须相互匹配。
我已经改了好几次了,希望我复制正确。请协助定制。对于被引用的其他权重,如果有必要,您可以为代码开发提供任意数值。非常感谢。
【问题讨论】:
-
请发布您尝试过的代码(通过编辑您的问题),并准确显示您使用的输入以及错误出现的位置...
标签: matlab