View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
Machine Learning with MATLAB

4.3 | 15 ratings Rate this file 94 Downloads (last 30 days) File Size: 882 KB File ID: #42744 Version:
image thumbnail

Machine Learning with MATLAB


Abhishek Gupta (view profile)


05 Aug 2013 (Updated )

These are the supporting MATLAB files for the MathWorks webinar of the same name.

| Watch this File

File Information

** 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


Rotate X Labels( Ax, Angle, Varargin ) and Plot Groups Of Stacked Bars inspired this file.

Required Products Fuzzy Logic Toolbox
Neural Network Toolbox
Parallel Computing Toolbox
Statistics and Machine Learning Toolbox
MATLAB release MATLAB 8.1 (R2013a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (30)
30 Nov 2016 Abhishek Gupta

Abhishek Gupta (view profile)


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:

Comment only
29 Nov 2016 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!


11 Oct 2016 Abhishek Gupta

Abhishek Gupta (view profile)


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.

Comment only
11 Oct 2016 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);

10 Oct 2016 Abhishek Gupta

Abhishek Gupta (view profile)


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.

Comment only
10 Oct 2016 Jie YANG

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.

Comment only
18 Jul 2016 Abhishek Gupta

Abhishek Gupta (view profile)

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.

Comment only
14 Jul 2016 biomechanic92

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

08 Jul 2016 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

Comment only
02 Jul 2016 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

Comment only

En el trabajo

Comment only
11 Apr 2016 marc vandenplas

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

11 Apr 2016 Shihab Khan

25 May 2015 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.

05 Mar 2015 Birsen

Birsen (view profile)

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

10 Feb 2015 Alecesa

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.


Comment only
09 Feb 2015 Abhishek Gupta

Abhishek Gupta (view profile)

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:

Comment only
05 Feb 2015 Benjamin

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.

05 Feb 2015 Benjamin

27 Jan 2015 Gareth Thomas

19 Jan 2015 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

Comment only
10 Dec 2014 Abhishek Gupta

Abhishek Gupta (view profile)

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:

Comment only
08 Dec 2014 Saida

Saida (view profile)

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'.

Comment only
25 Nov 2014 Azadeh

Azadeh (view profile)

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);

Comment only
14 Aug 2014 Mehmet

Mehmet (view profile)

24 Apr 2014 Abhishek Gupta

Abhishek Gupta (view profile)

Hi Remi,

The data for the classification example is available here:

I believe that I have mentioned this in the readme.

Comment only
21 Apr 2014 Rémi Larouche

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

28 Dec 2013 Wenwu

Wenwu (view profile)

Thanks, nice webinar and supplementary files.

16 Dec 2013 PRIYA

PRIYA (view profile)

08 Dec 2013 Sergey

Sergey (view profile)

05 Aug 2013 1.2

Added webinar link

30 Jul 2014 1.3

Updated webinar link

01 Sep 2016

Updated license

Contact us