mayra-ahmed asked . 2021-05-22

Why is the accuracy reported in the Classification Learner

Why is the accuracy reported in the Classification Learner app different from the accuracy of the exported model on the training data set?

When I train a model using the Classification Learner app in MATLAB, the accuracy reported is very low (near 20%). However, after exporting the model, I see nearly 100% accuracy on the training data.

deep learning , matlab , simulink

Expert Answer

Neeta Dsouza answered . 2024-12-21 16:47:06

The Classification Learner app is reporting the validation accuracy on the data based on the validation scheme that we choose when starting a new session in the app. The default setting in MATLAB R2018a is 5-fold cross-validation, and as such the accuracy reported in the app is based on the accuracy on the held-out validation set after training on the other 4 folds.
When the model is exported to the workspace, it is trained using the full data set. As a result, when we predict on that same data set, the accuracy is very high. However, if we were to predict on unseen data, the accuracy would be much lower.
To verify this, when loading the data into the Classification Learner app, you may set the 'Validation' option in the right-hand pane to 'No Validation'. After training, you should see that the accuracy reported in the app is near 100%.
You can also verify this by splitting your data into training and testing sets. Then, you may train the model in the app using only the training set and export the model. The accuracy of the exported model on the test set should be comparable to the accuracy reported in the app. I tried this myself by randomly splitting the data table using the following code:
>> perm = randperm(2282);
>> trainData = dataTable(perm(1:2000),:);
>> testData = dataTable(perm(2001:end),:);
Here is a bit more elaboration on how the app deals with the training data compared to how the generated code deals with the data:
When training a model in the app:
  1. The model is trained on the full dataset (i.e. all observations). This model is the one that is exported (, but is never visible to the user in any way within the app. There is no time lag when you click the export button because the model object was already created at training time.
  2. Performs validation (cross-validation, holdout etc). This is done purely to get the validation accuracy value as reported in the list of models, and to generate plots. The results of this validation step are not exported – you can only view it from within the app.
  3. When exporting a model from the app, the user gets the former model i.e. the one trained on the full dataset. The reasoning is that the validation accuracies (and plots) are there purely for choosing the type of model and hyperparameter selection in a statistically valid way.
How the accuracy is computed: # For the 5-fold cross-validation, let i=1:n be the indices of all observations, and partition these indices into 5 validation sets V_k for k=1,…,5. Let T_k = i / V_k i.e. a training set is defined as all points except the ones in the validation set V_k. Thus for each fold k, we have the training-validation set pairs T_k, V_k. We train on T_k and predict on V_k. This way we have predictions for all observations because we have predictions on each V_k, and the collection of V_k forms a partition on all observations. # Computing the accuracy is just a matter of comparing the above cross-validation predicted response vs. the observed response.
How the confusion matrix is computed (and other plots showing prediction information): # The same logic applies as above – since we have the predictions for each observation, we essentially call confusionmat(cross-validation-predictedResponse, observedResponse) to get the confusion matrix.
Generated code: # This emulates what the app does – i.e. you ‘import’ the dataset, preprocess it, train the model on the full dataset (which is returned), and perform validation (the validation accuracy is returned).


Not satisfied with the answer ?? ASK NOW

Frequently Asked Questions

MATLAB offers tools for real-time AI applications, including Simulink for modeling and simulation. It can be used for developing algorithms and control systems for autonomous vehicles, robots, and other real-time AI systems.

MATLAB Online™ provides access to MATLAB® from your web browser. With MATLAB Online, your files are stored on MATLAB Drive™ and are available wherever you go. MATLAB Drive Connector synchronizes your files between your computers and MATLAB Online, providing offline access and eliminating the need to manually upload or download files. You can also run your files from the convenience of your smartphone or tablet by connecting to MathWorks® Cloud through the MATLAB Mobile™ app.

Yes, MATLAB provides tools and frameworks for deep learning, including the Deep Learning Toolbox. You can use MATLAB for tasks like building and training neural networks, image classification, and natural language processing.

MATLAB and Python are both popular choices for AI development. MATLAB is known for its ease of use in mathematical computations and its extensive toolbox for AI and machine learning. Python, on the other hand, has a vast ecosystem of libraries like TensorFlow and PyTorch. The choice depends on your preferences and project requirements.

You can find support, discussion forums, and a community of MATLAB users on the MATLAB website, Matlansolutions forums, and other AI-related online communities. Remember that MATLAB's capabilities in AI and machine learning continue to evolve, so staying updated with the latest features and resources is essential for effective AI development using MATLAB.

Without any hesitation the answer to this question is NO. The service we offer is 100% legal, legitimate and won't make you a cheater. Read and discover exactly what an essay writing service is and how when used correctly, is a valuable teaching aid and no more akin to cheating than a tutor's 'model essay' or the many published essay guides available from your local book shop. You should use the work as a reference and should not hand over the exact copy of it.

Matlabsolutions.com provides guaranteed satisfaction with a commitment to complete the work within time. Combined with our meticulous work ethics and extensive domain experience, We are the ideal partner for all your homework/assignment needs. We pledge to provide 24*7 support to dissolve all your academic doubts. We are composed of 300+ esteemed Matlab and other experts who have been empanelled after extensive research and quality check.

Matlabsolutions.com provides undivided attention to each Matlab assignment order with a methodical approach to solution. Our network span is not restricted to US, UK and Australia rather extends to countries like Singapore, Canada and UAE. Our Matlab assignment help services include Image Processing Assignments, Electrical Engineering Assignments, Matlab homework help, Matlab Research Paper help, Matlab Simulink help. Get your work done at the best price in industry.