Hello
I am new to OCRs and am trying to use the MNIST dataset in matlab. I found a csv version of the data set which is usable in MATLAB then stored it as a .mat file (Somehow loads faster, I'm not so sure why if you do know do tell me). I wanted to try it on the fitcknn command as such
clc, clear
close all;
load 'mnist_train.mat'
knnmodel = fitcknn(mnist_train,"Var1")
I tried the Onramp course and tried to mimic how they did it but I get these error messages. I wanted to know if I can make this work and how.
Error using classreg.learning.FullClassificationRegressionModel.prepareDataCR (line 234)
X and Y do not have the same number of observations.
Error in classreg.learning.classif.FullClassificationModel.prepareData (line 821)
classreg.learning.FullClassificationRegressionModel.prepareDataCR(...
Error in ClassificationKNN.prepareData (line 926)
prepareData@classreg.learning.classif.FullClassificationModel(X,Y,varargin{:},'OrdinalIsCategorical',true);
Error in classreg.learning.FitTemplate/fit (line 233)
this.PrepareData(X,Y,this.BaseFitObjectArgs{:});
Error in ClassificationKNN.fit (line 911)
this = fit(temp,X,Y);
Error in fitcknn (line 264)
this = ClassificationKNN.fit(X,Y,RemainingArgs{:});
Error in OCR (line 6)
knnmodel = fitcknn(mnist_train,"Var1");

 採用された回答

larasupernovae
larasupernovae 2022 年 3 月 11 日

2 投票

So here is book, check out Chapter 6 if you are begining the MNIST in MatLab this is the best way to understand it all, hope this helps :) I also included my code from the book, a while a back when I was starting out with MNIST.

3 件のコメント

Jacob Ebilane
Jacob Ebilane 2022 年 3 月 11 日
Really helped! I tried replacing the training data with a different version of the csv format of the MNIST.
I was able to extract the letters and resize them to 28x28 then transpose before reshaping them into a single row.
I wanted to ask as well how can I help the the classifier if it makes a wrong prediction. I've had troubles with properly predicting the numbers 3,4,5 and 9. The only thing I could think of is manually adding data to the training set but it wouldn't be efficient.
larasupernovae
larasupernovae 2022 年 3 月 11 日
You probably won't do much by manual addition. The thing is the MNIST data set has an accuracy of 99%, you should be having just small anomalies when it comes down to it, using backpropagation a bit more efficiently might help (using it as a library just like in Python). The version I sent you is using the BP you make on your own, you can also use this type of code: see attachment https://we.tl/t-qA7w4fS5cO it's via we transfer since MatLab has a policy about uploading too much code :)
Jacob Ebilane
Jacob Ebilane 2022 年 3 月 13 日
I guess it has something to do with the algorithm I have for separating each digit. I think it has something to do with the data reaching the top of the image itself.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で Data Import and Export についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by