Hello,
I'm working with multi-class classification by using function fitcecoc.
Featureste is a 1063×22 matrix while Wte is a 1063×1 vector.
Running the code shown below, a message error is given, saying: 'To RESHAPE the number of elements must not change'
Error is given at the following line:
reshape(max(PosteriorRegion,[ ],2),size(x1Grid,1),size(x1Grid,2)))
How can I fix it? Thank you in advance
Mdl = fitcecoc(Featureste,Wte,'Learners',t,'FitPosterior',1,... 'ClassNames',{'1','2','3'},... 'Verbose',2)%Cross-validate Mdl using 10-fold cross-validation.
CVMdl = crossval(Mdl);%CVMdl is a ClassificationPartitionedECOC cross-validated ECOC classifier.
%Estimate the classification error.
loss = kfoldLoss(CVMdl); %Define a grid of values in the observed predictor space.
%Predict the posterior probabilities for each instance in the grid.
xMax = max(Featureste);xMin = min(Featureste);x1Pts = linspace(xMin(1),xMax(1));x2Pts = linspace(xMin(2),xMax(2));[x1Grid,x2Grid] = meshgrid(x1Pts,x2Pts);[~,~,~,PosteriorRegion] = predict(Mdl,[x1Grid(:),x2Grid(:)]);%For each coordinate on the grid
%plot the maximum class posterior probability among all classes.
figurecontourf(x1Grid,x2Grid,... reshape(max(PosteriorRegion,[],2),size(x1Grid,1),size(x1Grid,2)))hold ongh = gscatter(Featureste(:,1),Featureste(:,2),Wte,'krk','*xd',8)gh(2).LineWidth = 2;gh(3).LineWidth = 2;hold off
Best Answer