如何为Python设置LIBSVM [英] How to Setup LIBSVM for Python

查看:254
本文介绍了如何为Python设置LIBSVM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Mac OS X上使用Make构建了 libsvm .

I built libsvm on Mac OS X with Make.

$ tar xzfv libsvm-3.17.tar.gz
$ cd libsvm-3.17
$ make

这构建了各种libsvm二进制文件:

This built the various libsvm binaries:

$ ls
COPYRIGHT           heart_scale svm-predict.c   svm-train.c tools
FAQ.html            java        svm-scale   svm.cpp     windows
Makefile            matlab      svm-scale.c svm.def
Makefile.win    python      svm-toy     svm.h
README      svm-predict svm-train   svm.o

我也在/usr/local中与此链接:

$ ls -la /usr/local/
...
svm -> /usr/local/libsvm-3.17/

并将Python绑定附加到我的路径:

And appended the Python bindings to my path:

import sys
sys.path.append('/usr/local/svm/python')

但是Python绑定找不到"LIBSVM"库:

But the Python bindings cannot find the "LIBSVM" library:

$ python test.py 
Traceback (most recent call last):
   File "test.py", line 8, in <module>
      import svmutil
   File "/usr/local/svm/python/svmutil.py", line 5, in <module>
      from svm import *
   File "/usr/local/svm/python/svm.py", line 22, in <module>
      raise Exception('LIBSVM library not found.')
Exception: LIBSVM library not found.

有人可以告诉我如何设置吗?在libsvm的python自述文件中,唯一的描述是

Can anyone tell me how to set this up? In the python readme for libsvm the only description is

Installation 
============

On Unix systems, type

> make

The interface needs only LIBSVM shared library, which is generated by
the above command. We assume that the shared library is on the LIBSVM
main directory or in the system path.

我想念什么?

推荐答案

您可能不希望通过Python访问libsvm(我通过MacPorts安装了libsvm,而import svmutil失败了),您可能想安装流行的 scikit-learn 软件包,其中包含

Instead of going through libsvm in order to access it with Python (I installed libsvm through MacPorts, and import svmutil fails), you might want to install the popular scikit-learn package, which contains an optimized version of libsvm with Python bindings.

使用 MacPorts 的安装非常简单:sudo port install py27-scikit-learn(将py27适应所使用的任何Python版本)

The install is very simple with MacPorts: sudo port install py27-scikit-learn (adapt py27 to whatever version of Python you use).

这篇关于如何为Python设置LIBSVM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆