LibSVM3.21 Use notes----for python3.4 configuration __python

Source: Internet
Author: User

Need to use SVM to do a text categorization project, so decided to use libsvm3.21, on the Win64 training model, Android to do prediction classification, this article is for the next configuration Guide to prevent this machine doc lost.

Native environment: Win10 64bit, python3.4, libsvm3.21 (http://www.csie.ntu.edu.tw/~cjlin/)

Android LIBSVM:HTTPS://GITHUB.COM/YCTUNG/ANDROIDLIBSVM

Install Python (using python3.4)

Run "cmd" and enter Python directly to see if Python is 32-bit or 64-bit

(2.1) If Python is 32-bit, locate the dynamic link library Libsvm.dll in the WINDOWS folder under the Libsvm-3.21 folder and add it to the system directory, such as ' C:\WINDOWS\system32\ ', You can use LIBSVM in Python

(2.2) If Python is 64-bit, you need to first compile the 64-bit dynamic-link library Libsvm.dll. The method is as follows:

Under Microsoft Visual Studio 2012/visual Studio Tools in the list of programs, open VS2012 X64cross toolscommand Prompt, note that you must be a 64-bit command Prompt.

(At this point, you may encounter an error: "Error cannot determine the location of the VS Commontools folder", if the Win7 64-bit system, the installation is VS2012, the solution to this problem is : In the computer environment variable path add: C:\Windows\System32, I win10 64 did not encounter this problem)

Dos to LIBSVM folder libsvm-3.21

Input nmake-f Makefile.win Clean all

In this case, a 64-bit dynamic link library will be generated in the libsvm-3.21 Windows directory. Copy the newly generated libsvm.dll to the system directory (for example, ' C:\WINDOWS\system32\ ').

Test

Open Idle

>>> from sys import path

>>> path.append (' D:\LIBSVM\libsvm-3.21\python ')

>>> 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)

accuracy = 84.2857% (59/70) (classification)

Get...

The DataLabel and dataset in Notes:svm_predict (DataLabel, DataSet, model) is at least the list type and cannot be a single value, so if it is a single value, it needs to be converted to matrix, for example, to a single value x, Y, Should be written in svm_predict ([y], [x], 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.