matrix dimension must agree
2 views (last 30 days)
Show older comments
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)
1 Comment
Answers (0)
See Also
Categories
Find more on Statistics and Machine Learning Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!