mac python安装libsvm_如何为Python设置LIBSVM

I built libsvm on Mac OS X with Make.

$ tar xzfv libsvm-3.17.tar.gz

$ cd libsvm-3.17

$ make

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

I also linked to this in /usr/local:

$ ls -la /usr/local/

...

svm -> /usr/local/libsvm-3.17/

And appended the Python bindings to my path:

import sys

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

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

$ python test.py

Traceback (most recent call last):

File "test.py", line 8, in

import svmutil

File "/usr/local/svm/python/svmutil.py", line 5, in

from svm import *

File "/usr/local/svm/python/svm.py", line 22, in

raise Exception('LIBSVM library not found.')

Exception: LIBSVM library not found.

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.

What am I missing?

解决方案

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.

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值