File Exchange

image thumbnail

Machine Learning with MATLAB

version (882 KB) by Abhishek Gupta
These are the supporting MATLAB files for the MathWorks webinar of the same name.


Updated 01 Sep 2016

View Version History

View License

** Update: The webinar recording is available at:
In this webinar you will learn how to get started using machine learning tools to detect patterns and build predictive models from your datasets. In this session, you will learn about several machine learning techniques available in MATLAB and how to quickly explore your data, evaluate machine learning algorithms, compare the results, and apply the best machine learning for your problem.

Highlights include unsupervised and supervised machine learning techniques including:
• K-means and other clustering tools
• Neural Networks
• Decision trees and ensemble learning
• Naïve Bayes Classification
• Linear, logistic and nonlinear regression

Cite As

Abhishek Gupta (2021). Machine Learning with MATLAB (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (45)


hi I used this code but keep getting the error in svmtrain(). it says ''Undefined function or method 'svmtrain'". I have MATLAB2019a and have all the required toolboxes. When I even tried fitcsvm() then i get the error kktviolationlevel is not a valid parameter.
Please help out.

kumari kalyani

Seunghoon Lee

Abhishek Aiyer

Hi I keep getting the error "Undefined function or variable 'catPred'".
I see in the webinar that you have the variable in your workspace, however, it doesn't seem to be defined in your code. Also when selecting the Neural Net Pattern Recognition, I can't seem to be able to select any variables to run the analysis on. Could you Kindly advise on this please?

huajun Lei

Abhishek Gupta

Linying, BondData.mat is part of the submission. You simply need to load the MAT-file in MATLAB.

linying lu

could you help to share the BondData, thanks

Abhishek Gupta

Kommanaboina, this maybe something specific to your setup. Please contact technical support for further help:

In clusteration problem in similarity matrix in line no 9 error is showing.Error using plotSimilarityMatrix (line 9)
Not enough input arguments.this error is showing.Can you pls help me to fix the problem?


Abhishek Gupta

The data for the classification example is available here:
I have mentioned this in the readme.


Hi sir,
which dataset you have used in your code.

Abhishek Gupta

srikantanss ss: Please contact technical support for further help:

K. Kojima

srikantanss ss

i could not run this in 2016a
please advise

Abhishek Gupta


I tried executing the code in the recent releases of MATLAB and am unable to reproduce the errors. This maybe something specific to your setup. Please contact technical support for further help:

Jianshe Feng

Hi Gupta,

Thanks for your webinar, which is very helpful. However, when I try your code in MATLAB 2016b, here is the error:

Error using textscan
Invalid file identifier. Use fopen to generate a valid file identifier.

Error in ImportBankData (line 53)
dataArray = textscan(fileID, formatSpec, endRow(1)-startRow(1)+1, 'Delimiter', delimiter, 'EmptyValue'
,NaN,'HeaderLines', startRow(1)-1, 'ReturnOnError', false);

Error in MachineLearning (line 65)
bank = ImportBankData('bank-full.csv');

Could you help to fix it? Thanks!


Abhishek Gupta


I wrote these functions specific to the data set at hand. Minor modifications may be needed for these functions to work with another data set. Please contact technical support for further help:

You should be able to apply similar principles with larger number of inputs and/or classify into as many categories, as needed.

Renato Siqueira

I could replicate the results but when I change the input, return na error. My database has 2.400 arguments

Trial>> comparisonPlot
Not enough input arguments.

Error in comparisonPlot (line 6)
[nRows, nCols] = size(Cmat);

Abhishek Gupta


Most of the machine learning techniques reside in the Statistics and Machine Learning Toolbox. Machine learning techniques related to neural networks reside in Neural Network Toolbox.

I am only leveraging Fuzzy C-means clustering from Fuzzy Logic Toolbox.

In these examples, Parallel Computing Toolbox is is used to speed up the analysis by explicitly leveraging the additional cores/processors on a desktop/laptop. It is not required.

If you have fewer toolboxes, you should still be able to re-use parts of these examples.


Dear Abhishek Gupta,

Thank you for sharing your code. May I ask that the required products should be installed especailly for MATLAB 2012b due to I am lack of the toolboxes.

Abhishek Gupta

biomechanic92: In this submission, MachineLearning.m contains the whole classification example including everything covered in Presentation.m. Thus, I didn't include Presentation.m as it would be redundant.


Is there is a reason why Presentation.m file is not on here? or is it located somewhere else like the bank.csv file?

Eshaan Ghosh

Steps to follow
1. Go to
Data folder>
2. Open any of the excel files
3. Select Column A
4. Data> Text to Columns> Delimited
5. Pres Next, Select Semicolon, select Next
6. Finish

You got the bank file for your computation

andres razo

diculpen en el descargable no existe el archivo bank-full.csv y el bank.csv por lo que da el error al ejecutar el programa


En el trabajo

marc vandenplas

top notch work.
and Abhishek answered my questions in an off-line email - that's what makes Matlab great.

Shihab Khan

Mark Knecht

Sadly, another case of creeping package usage in MatLab. Great for people who have access to everything MatLab offers. Not so good for the rest of us.


The presentation.m is not in the download folders as in the webinar.
The webinar is not for someone is new in that subject, the explanations are for the ones who already knows machine learning


Hi Gupta,

I am new to Matlab but in trying to replicate the code script provided, I had the same error as reported by Saida. tried the Bank.csv and Bank-full.csv and the problem repeats as follows:

Trial>> bank = ImportBankData('bank-full.csv');
names = bank.Properties.VarNames;
Undefined function 'ImportBankData' for input arguments of type 'char'.

Any support/suggestion would be appreciated.


Abhishek Gupta

Hi Benjamin,

Excellent question. Currently, there is no way to inform SEQUENTIALFS about the categorical predictors. Thus, it treats all predictors as numeric. The development team is aware and they plan to add this capability in a future release of our tools.

Hi Himakshi,

It is hard for me to predict (no pun intended) the cause of the error at your end. Please feel free to reach out to our technical support team:


How are the categorical predictors handled in the sequentialfs step in MachineLearning.m line 430 if the logical matrix catPred isn't used in the critfun or in sequentialfs? Thanks for the clarification.


Gareth Thomas

himakshi Shekhawat

hi, I have run your code as i have to do similar work but your code is not reading data from the file bank-full.csv and is returning 0 rows. As the error is
??? Error using ==> cvpartition>cvpartition.cvpartition at 137
The number of observations must be a positive integer greater than one.
I am not able to understand why it is not reading data from rows of csv file

Abhishek Gupta

Hi Azadeh and Saida,

I tried executing all the code in the recent releases of MATLAB and am unable to reproduce the errors. This maybe something specific to your setup. Please contact technical support for further help:


I keep trying to follow your code but the very first line gives me an error.

>> bank=ImportBankData('bank-full.csv');
Undefined function 'ImportBankData' for input arguments of type 'char'.


I run MachineLearning.m on sample dataset bank-full.csv and got this error:

Default value is not a member of type "nntype.performance_fcn".
Error using nnetParamInfo (line 28)
Too many input arguments.

Error in patternnet>get_info (line 85)
info = nnfcnNetwork(mfilename,'Pattern Recognition Neural Network',fcnversion, ...

Error in patternnet (line 41)
if isempty(INFO), INFO = get_info; end

Error in NNfun (line 18)
net = patternnet(hiddenLayerSize);

Error in MachineLearning (line 191)
[~, net] = NNfun(XtrainNN,YtrainNN);


Abhishek Gupta

Hi Remi,

The data for the classification example is available here:

I believe that I have mentioned this in the readme.

Rémi Larouche

The CSV file is missing ('bank-full.csv').


Thanks, nice webinar and supplementary files.



MATLAB Release Compatibility
Created with R2013a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!

Machine Learning/Classification/html/

Machine Learning/Clustering/html/