【问题标题】:Customizing the code given in "Efficient multiclass weighted majority voting implementation in MATLAB" [duplicate]自定义“MATLAB 中的高效多类加权多数投票实现”中给出的代码 [重复]
【发布时间】: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


【解决方案1】:

我认为您链接到的代码已经足够通用,可以处理不同数量的选民和不同数量的类。如果我改变 only 输入如下:

w=[7 2 6 5];

votes = ['A' 'B' 'B' 'A'
         'C' 'A' 'A' 'B'
         'B' 'B' 'A' 'C'
         'A' 'A' 'C' 'A'];

options = ['A', 'B', 'C']';

然后它仍然有效,现在在概念上聚合了 4 个分类器,只有 3 个类。即这仍然有效:

%//Make a cube of the options that is number of options by m by n
OPTIONS = repmat(options, [1, size(w, 2), size(votes, 1)]);

%//Compare the votes (streched to make surface) against a uniforma 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(options, 1), 1), B), 2))'

%'//Find the options with the highest weighted sum
[xx, i] = max(W, [], 2);
options(i)

因此,您的错误可能源于您输入的格式。请在运行其余代码之前提供您的woptionsvotes 矩阵的 sn-ps?

【讨论】:

  • 谢谢丹。问题出在我的输入上。
猜你喜欢
  • 2013-03-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-02-15
  • 2021-09-27
  • 2011-06-24
  • 2013-01-16
相关资源
最近更新 更多