我 build 了 libsvm在 Mac OS X 上使用 Make。
$ tar xzfv libsvm-3.17.tar.gz
$ cd libsvm-3.17
$ make
这构建了各种 libsvm 二进制文件:
$ 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 绑定(bind)附加到我的路径中:
import sys
sys.path.append('/usr/local/svm/python')
但是 Python 绑定(bind)找不到“LIBSVM”库:
$ 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 自述文件中,唯一的描述是
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.
我错过了什么?
最佳答案
与其通过 libsvm 来使用 Python 访问它(我通过 MacPorts 安装了 libsvm,import svmutil
失败),您可能想要安装流行的 scikit-learn包,其中包含 libsvm with Python bindings 的优化版本.
使用 MacPorts 安装非常简单: sudo port install py27-scikit-learn
(使 py27
适应您使用的任何 Python 版本)。
关于python - 如何为 Python 设置 LIBSVM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15755130/