Python LIBSVM usage Summary

Source: Internet
Author: User

Python LIBSVM usage Summary

1) download the installation package python-2.7.3.msi under windows from the python official website and install


2) Open IDLE (python GUI) and enter
>>> Import sys
>>> Sys. version
If your python is 32-bit, the following characters will appear:
'2. 7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)]'
In this case, the python interface setting of LIBSVM is very simple. Find the dynamic link library libsvm. dll in the windows folder under the libsvm-3.16 folder and add it to the system directory, such as 'C: windowssystem32', you can use libsvm in python


3) If your python is 64-bit, that is, open IDLE (python GUI) and enter
>>> Import sys
>>> Sys. version
The following characters are displayed:
'2. 7.3 (default, Apr 10 2012, 23:24:47) [MSC v.1500 64 bit (AMD64)]'
At this time, you need to compile the 64-bit dynamic link library libsvm. dll by yourself. The method is as follows:
Find Visual Studio x64 Win64 Command Prompt (2010) in Microsoft Visual Studio 2010/Visual Studio Tools in the program list. Be sure to use the 64-bit command prompt.
Libsvm-3.16 from cd to LIBSVM folder
Enter nmake-f Makefile. win clean all
A 64-bit dynamic link library is generated under the windows directory of the libsvm-3.16. Copy the newly generated libsvm. dll to the system directory (for example, 'c: windowssystem32.

 

========================================================== ============================================
====================================================== Awesome split line ==== ======================================

========================================================== ============================================

4) Simple SVM operations are directly implemented according to this step.
Enable IDLE
>>> Import OS
>>> OS. chdir ('C: Program Fileslibsvm-3.16python ')
>>> From svmutil import *
>>> Y, x = svm_read_problem ('../heart_scale ')
>>> M = svm_train (y [: 200], x [: 200], '-c 4 ')
>>> P_label, p_acc, p_val = svm_predict (y [200:], x [200:], m)


5) python Interface Description
The python folder in the libsvm-3.16 mainly contains two files: svm. py and svmutil. py.
The svmutil. py interface mainly includes high-level functions. The usage of these functions is similar to the MATLAB interface of LIBSVM.
Svmutil mainly includes the following functions:
Svm_train (): train an SVM model
Svm_predict (): predict testing data
Svm_read_problem (): read the data from a LIBSVM-format file.
Svm_load_model (): load a LIBSVM model.
Svm_save_model (): save model to a file.
Evaluations (): evaluate prediction results.
The svm. py interface mainly includes some low-level applications. The built-in ctypes library of python is used in svm. py, so that python can directly access the C structure and interface functions defined in svm. h. Svm. py mainly uses four data structures: svm_node, svm_problem, svm_parameter, and svm_model.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.