can you post the output of size(mnist_test_y) and size(pred)
matrix dimension must agree
3 次查看(过去 30 天)
显示 更早的评论
Hi,
I am trying to do CKNN. The script runs smoothly at first. But when I try to see confusion matrix, Iget error saying Matrix dimension must agree.
Why is this happenning?
load('Assignment 2\ENN543_Assignment2_Data\Q3\mnist_train.mat')
mnist_images_train = reshape(imgs,1024,50000);
mnist_train_y = labels;
load('Assignment 2\ENN543_Assignment2_Data\Q3\mnist_test.mat')
mnist_images_test = reshape(imgs,1024,10000);
mnist_test_y=labels;
load("Assignment 2\ENN543_Assignment2_Data\Q3\svhn_test.mat")
svnh_images_test=reshape(imgs,1024,26032);
svnh_test = labels;
%%-CKNN
% cknn = fitcknn(mnist_images_train',categorical(mnist_train_y), 'Distance', 'cityblock');
cknn = fitcknn(mnist_images_train',mnist_train_y,'NumNeighbors',5);
pred = cknn.predict(mnist_images_test')
disp(sum(pred == mnist_test_y)/length(mnist_test_y))
%%Matrix dimension must agree
confusionchart(mnist_test_y, pred)
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Statistics and Machine Learning Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!