Jump to content

Support Vector Machine classifier


torekp

Recommended Posts

What is it? What does it do and what is it for?

It predicts class membership based on associated variables. In my job, we want to classify scrap metal bits based on color (red green and blue), for example. Say we want to separate brass versus copper from a mixed pile. The Support Vector Machine is a "supervised" classifier meaning that we start with sets of known members of each class. Use those to "train" the classifier and create a model. The model defines a hyperplane in Red-Green-Blue space with brass on one side and copper on the other. (Technically, it could be more than one hyperplane, but for me, in practice, just one.)

Suppor Vector Machine wiki. Kernel Discriminant Analysis is a closely related concept.

I'm attaching another version below. This one limits the parameter search in C and gamma to make it go faster, although my work there could stand some improvement. It also, in some sub-sections, assumes that you only have three dimensions (red green and blue) to your data. If you want to use this on data with more than three dimensions, it shouldn't be hard to find the limiting subVIs and modify or delete them.

Color_SVM_3d Folder.zip

Link to comment
  • 5 months later...
  • 3 months later...

Sorry I didn't see this sooner. When you download the llb, you may also have to create a directory C:\WORK Or maybe not, it might create it for you, I haven't checked. Ignore the double-backslashes, those are just escape characters to please the C program inside some code interface nodes. The actual file is C:\WORK\RBFModel.txt

Link to comment
  • 3 years later...

Sorry to revive such an old thread, but this is one of the top results when googling for libsvm and LabVIEW. I've implemented a new interface to libsvm using call library function nodes instead of CINs. A parameter grid-search as in the original post isn't included, but should be fairly simple to build on top of the new interface. Note that the old interface passed data through text-files, while this new interface passes the data directly.

 

Feel free to try it out and report bugs. I'll continue to add features once I have some time on my hands. I'll probably submit it as an official interface, once I feel that it's stable enough and I've settled on the API.

 

The library is available at http://github.com/oysstu/LabVIEW-libsvm. Just download the provided VIPM package under releases.

  • Like 2
Link to comment
  • 2 months later...

Sorry to revive such an old thread, but this is one of the top results when googling for libsvm and LabVIEW. I've implemented a new interface to libsvm using call library function nodes instead of CINs. A parameter grid-search as in the original post isn't included, but should be fairly simple to build on top of the new interface. Note that the old interface passed data through text-files, while this new interface passes the data directly.

 

Feel free to try it out and report bugs. I'll continue to add features once I have some time on my hands. I'll probably submit it as an official interface, once I feel that it's stable enough and I've settled on the API.

 

The library is available at http://github.com/oysstu/LabVIEW-libsvm. Just download the provided VIPM package under releases.

Could you please send me an LVlibSVM.dll file? I don't have an vs2013.

Thank you very much

zhengenhao2@126.com

Link to comment
  • 2 weeks later...

 

The library is available at http://github.com/oysstu/LabVIEW-libsvm. Just download the provided VIPM package under releases.

 

Thanks oysstu.  I'm having the same problem as zhengenhao2.  Trying to use one of the Example VIs, it asks me to locate LVlibSVM.dll, but no such file seems to exist.  This is for 32-bit Labview 2014.  The default path where it tries to look, is in the folder that contained the VI Package Builder, in a subfolder called .Labview - note the dot.  No such subfolder exists.

Link to comment
  • 2 weeks later...

Well, I've tried installing lvlibsvm-0.4.0.1 on both LabVIEW 2014/2015 32-bit and 64-bit now, and both seem to work for me.

 

The vip package contains both the 32-bit and 64-bit DLLs, which are both installed into "..\LabVIEW 201#\vi.lib\oysstu\LVLibSVM\bin" under x86 and x64 folders, respectively. I then execute a post-build script, which deletes the folder of DLLs not needed. The library is then mass-compiled (again) to correctly locate the DLL. The post-build script can be found on github (link). This is my first time using VIPM, so I'm not sure where the error lies as I'm unable to reproduce the problem on my end.

 

Just to make sure, you have installed the library using the vip file under releases, right? If you simply download the zip archive, you do not get any binaries - and would have to build it yourselves.

 

Edit: I've attached a zip containing the binaries temporarily until this can be resolved. Note that LabVIEW does not play nice with 32/64-bit dlls that has the same name (which is why the uneeded DLLs are deleted in the first place).

 

Edit 2: Removed the attached binaries, as they were outdated. The binaries are now released in a standalone zip archive in addition to the vipm file, see github for download.

Edited by oysstu
Link to comment

Dear Mr.Torekp,

 

Now I'm doing my final project for bachelor degree, my topic is about Support Vector Machine to identify two different sample. I'm using labview on it, and I found this library for SVM Labview, but I have problem to use the library. Would you please give me some advice or tutorial to use the library. Thank you for your attention.

 

Best Regards,

Laely

 

Link to comment
  • 2 months later...

Dear Mr.Torekp,

[...]

 

Hello Laely, sorry I didn't see this earlier.  I haven't been that regular on lavag.org lately, but I'll try to show up more often for a while.  I'd be happy to help, but I've only been able to make the old interface work, not the one posted by oysstu.

 

If you download from my post#3 in this thread, then extract that zip to any folder (say C:\Laely), then open the VI in the top level folder, it should work for you.  Just change the start path to your folder (e.g. C:\Laely\Color_SVM_3d Folder\Color_SVM_3d Folder\data) before running.  The code is written in LV 8.5.  Press the buttons Read, Make Model, View Model, etc. in order.  When you Read (the data) select the file AsandBs.txt.  A popup VI will ask you to name the two categories - put any names you want.

 

If you want to make your own data file, look at the format of AsandBs.txt.  The category goes in the first column.  The classification must be binary; only zero vs nonzero in the first column will make a difference.

Link to comment

The vip package contains both the 32-bit and 64-bit DLLs, which are both installed into "..\LabVIEW 201#\vi.lib\oysstu\LVLibSVM\bin" under x86 and x64 folders, respectively. I then execute a post-build script, which deletes the folder of DLLs not needed.

 

The github files appear to contain only a vipb file, not a vip file.  I was able to build a vip file in LV2015+VI Package Manager, but no DLLs appeared.  I tried installing the attached DLL files in the zip into vi.lib/oysstu/... , but when I opened the example VI in the "dense"  category, it wanted a different DLL named LabVIEW-libsvm-dense.dll.  I tried linking to the DLL from the zip file named LVLibSVM.dll instead, but while the broken arrow went away, it generate a 1097 error on running.  (1097=problem in external code linked by Code Interface Node.)

 

This is on Windows XP 32-bit, using the DLLs in the x86 folder.

Link to comment

The github files appear to contain only a vipb file, not a vip file.  I was able to build a vip file in LV2015+VI Package Manager, but no DLLs appeared.  I tried installing the attached DLL files in the zip into vi.lib/oysstu/... , but when I opened the example VI in the "dense"  category, it wanted a different DLL named LabVIEW-libsvm-dense.dll.  I tried linking to the DLL from the zip file named LVLibSVM.dll instead, but while the broken arrow went away, it generate a 1097 error on running.  (1097=problem in external code linked by Code Interface Node.)

 

This is on Windows XP 32-bit, using the DLLs in the x86 folder.

 

The vipb file is the build file I use in VIPM to generate the installable vip packages, and isn't intended for users. The vip packages I build can be found under releases (https://github.com/oysstu/LabVIEW-libsvm/releases).

 

I tested the library under win xp 32-bit in a virtual machine now with no issues. It's too bad that github features a big download zip button on the main page, when the most common way to distribute binaries is through releases.

  • Like 1
Link to comment

The vipb file is the build file I use in VIPM to generate the installable vip packages, and isn't intended for users. The vip packages I build can be found under releases (https://github.com/oysstu/LabVIEW-libsvm/releases).

 

I tested the library under win xp 32-bit in a virtual machine now with no issues. It's too bad that github features a big download zip button on the main page, when the most common way to distribute binaries is through releases.

 

The download ZIP button is not to download an installer but rather an image of the source files as present in the github project repository. Not sure I would consider this unfortunate as one might expect users going to github to know a bit about software development and the difference between a source code tree and a build package.

 

Sourceforge has it in that respect a bit more clearly structured where you have the code section where you can browse the source code and download an image of it and the files section where the project maintainer usually puts installers or source tree executable packages for end users to download and use. If only it wasn't acquired by slashdot and turned into a cash machine with advertisment and download wrappers for popular projects, with the wrappers trying to force all kinds of adware on a users computer.

Link to comment
  • 3 years later...

After getting a PM from Xuan-Thai, I realized that if you want to sort more than two classes, my other statistical modeling post might be useful as a "prequel" to using this SVM code.  That other post:

Using the Multiple Discriminant Analysis (MDA) example could help you pick which two groups of classes to separate first.  Then you would rinse and repeat, always separating along the most easily discernible lines.  For example in the graph from my other thread that you can (depending on your browser?) partially see above, it makes sense to separate white from red-and-green first. The MDA example depends on the following Moore Good Ideas packages (get them with VI Package Manager):

MGI Cluster, MGI Error Handling, MGI File, MGI String, MGI Read/Write Anything.  I'm attaching a Labview 2017 version of the MDA_example code, or you can get a LV2012 version from the original thread (which also has a PLSDA classifier).

MDA_example_without_MGI.zip

Link to comment

Multi-class discrimination in libsvm is done by training one classifier for each pair of labels. Possible, but not very efficient/scalable, as that means that you have to train n(n-1)/2 classifiers, where n is the number of classes. For your problem, with four classes, it may work, but expect to spend some time training while tuning parameters

- Oystein

Link to comment

For what it's worth, for some classifiers (PLSDA for example), I've gotten better results by using a sequence of binary classifiers, rather than just doing all-vs-all.  Dunno if this applies to SVM, but I suspect it could.  Might be worth the effort.

Link to comment
  • 2 years later...

I installed the LIBSVM by  oysstu and it has worked well for the classification problems.

But I don't know how to run that library for the regression problem such as linear regression.

Please help me with this issue if everyone has done work the Labview libsvm for the regression.

Thank you very much

P/s: The attached file is the dataset that I want to do regression for the target variable.

 

dataset for regression problem.csv

Link to comment
On 9/16/2010 at 1:04 AM, torekp said:

Here is a Labview program that I found very useful. I made minor modifications to make it more useful to me. Its core is LIBSVM by Chih-Jeh Lin and Kiwoong Kim.

post-4616-037254300 1284573754_thumb.png

Since writing these, I developed some further advancements but I haven't wrapped those in a neat package yet. Let me know if you're interested.

Labview4LIBSVM Folder.zip 426.16 kB · 730 downloads

How can I use this library for the regression problem. The attached file is the dataset that I want to do a regression on the target variable.

Thank you very much

dataset for regression problem.csv

Link to comment
  • 3 months later...
On 8/29/2021 at 12:21 AM, Xuan-Thai Nguyen said:

How can I use this library for the regression problem.

I'm not sure, but I think you can use the liblinear functions in https://github.com/oysstu/LabVIEW-libsvm (oysstu's package), and set the solver type to L2R_LR (not "...Dual").  The solver type is a parameter in the cluster "parameters" for liblinear_train.vi.  This seems, on first glance, to be doing one-class regression (which is what you want), rather than two-class classification.

Edited by torekp
Link to comment
  • 4 weeks later...

Join the conversation

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

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