Jump to content

Statistical modeling example code

Recommended Posts

Here's some code I developed for classification problems.  The methods used are Multiple Discriminant Analysis, and Partial Least Squares Discriminant Analysis.  At least, they're supposed to be.  I've tried them and they seem to work, but I offer no guarantees.  If anyone finds these really useful, I might try to upgrade them to the point where they'd be fit for the Code Repository.






Labview 2012 SP1 Full, requires Matrix/Linear Algebra functions, and many MGI utilities (use VI Package Manager to install MGI utilities).  The example data is taken from the classic "IRIS" data set (but for PLS, the Virginica category is omitted:  this version of PLS can only do binary classification).  Just press "Read File" and then say "Cancel" to get the default example data set for each method.


Find some directory somewhere and unzip the zip file there, then open the project.  All will be clear, I hope.



Edited by torekp
Fix PLS algorithm
Link to comment

Note: although the PLSDA result for the IRIS data set looks reasonable - it seems to be doing a good job clustering the two categories in different parts of the LatentFactor space - I have had difficulties trying to apply this to my real work.  The problem might be in my other, work-related Labview code, but it might be in the above code that I've offered you.  If anyone has a Matlab PLSDA code or something that they know for sure works, and if it uses the PLS1 algorithm, and they'd like to compare results to make sure they're identical (or not), that would be nice.


I have a vague memory of having done exactly that check with my Multiple Discriminant Analysis algorithm, comparing published results, and seeing agreement.  So that one's probably OK.

Edited by torekp
Link to comment
  • 4 months later...
  • 1 year later...
On 9/1/2015 at 12:04 PM, Wouter said:

Small note: there is a machine learning toolkit available, https://decibel.ni.com/content/docs/DOC-19328

yes, but either the old version (machine learning toolkit) nor the new the LabVIEW Analytics and Machine Learning Toolkit   does contain a PLS1 Algorithm

- but both have a PCA.vi

so you could do a PCA on the input, and then make a linear regression with the PCA'S scores. That's  a PCR: https://en.wikipedia.org/wiki/Principal_component_regression

If you had several categorial classes, you have to do for each class a PCA and a linear regression.


I think, that's equal to, what a PLS-1 does in one attempt:

" ...it finds a linear regression model by projecting the predicted variables and the observable variables to a new space.."




On 8/31/2015 at 5:40 PM, torekp said:

The above PLS code has been corrected for one error.  Below I attach the one corrected VI.  Other errors might remain.




I can't get the Discriminat example to work, but I did get torekkp's PLS1.vi to work with my custom data (about 3000 spectra, each one is a 1d array of 1024 bins)

looks like it does compute, what it is supposed to do - I compared the scores to the scores of  a PLS1 routine I have written once upon a time - 


Unfortunately, I can't share the data I used, maybe I find the time to put together some online available spectra dataset 



Edited by Lexington Flenner
Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

By using this site, you agree to our Terms of Use.