# Linear Discriminant Analysis: MATLAB, R and Python codes — All you have to do is just preparing data set (very simple, easy and practical)

I release MATLAB, R and Python codes of Linear Discriminant Analysis (LDA). They are very easy to use. You prepare data set, and just run the code! Then, LDA and prediction results for new samples can be obtained. Very simple and easy!

You can buy each code from the URLs below.

#### MATLAB

https://gum.co/uVtRo
Please download the supplemental zip file (this is free) from the URL below to run the LDA code.
http://univprofblog.html.xdomain.jp/code/MATLAB_scripts_functions.zip

#### R

https://gum.co/bZPL
Please download the supplemental zip file (this is free) from the URL below to run the LDA code.
http://univprofblog.html.xdomain.jp/code/R_scripts_functions.zip

#### Python

https://gum.co/JHFt
Please download the supplemental zip file (this is free) from the URL below to run the LDA code.
http://univprofblog.html.xdomain.jp/code/supportingfunctions.zip

### Procedure of LDA in the MATLAB, R and Python codes

To perform appropriate LDA, the MATLAB, R and Python codes follow the procedure below, after data set is loaded.

1. Autoscale explanatory variable (X)
Autoscaling means centering and scaling. Mean of each variable becomes zero by subtracting mean of each variable from the variable in centering. Standard deviation of each variable becomes one by dividing standard deviation of each variable from the variable in scaling.

2. Construct LDA model

3. Calculate confusion matrix between actual Y and calculated Y
Accuracy rate, detection rate, precision and so on can be calculated from each confusion matrix, if necessary.

4. In prediction, subtract the mean in the autoscalling of X in 1. from X-variables, and then, divide X-variables by the standard deviation in the autoscalling of X in 1., for new samples

5. Estimate Y based on LDA model in 2.

### How to perform LDA?

#### 1. Buy the code and unzip the file

MATLAB: https://gum.co/uVtRo

Python: https://gum.co/JHFt

#### 4. Prepare data set. For data format, see the article below.

https://medium.com/@univprofblog1/data-format-for-matlab-r-and-python-codes-of-data-analysis-and-sample-data-set-9b0f845b565a#.3ibrphs4h

#### 5. Run the code!

Estimated values of Y for “data_prediction2.csv” are saved in ”PredictedY2.csv”.