Jump to content
News about the LabVIEW Wiki! Read more... ×
Sign in to follow this  
torekp

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.

MDA__examplep.png

PLS__examplep.png

PLS__exampled.png

PLS1d.png

 

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.

statsExampl.zip

 

Edited by torekp
Fix PLS algorithm

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

 

PLS1.vi

Edited by torekp
error corrected in PLS1.vi

Share this post


Link to post
Share on other sites
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.."

https://en.wikipedia.org/wiki/Partial_least_squares_regression

 

 

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.

 

PLS1.vi

 

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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

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