python3.2+libsvm3.17的配置

7 篇文章 0 订阅

想了解一下支持向量机这个东西,网上查阅后发现湾湾的libsvm倍受好评,于是赶紧下载下来。由于版本的原因的,根据网上搜索到的配置方法,都不能顺利启动,各种报错。后经不断尝试修改,终于搞定。具体过程如下:

ps:使用环境为win7 x64

1、下载相关软件。

  1. python3.2,安装目录:d:/Python32
  2. libsvm3.17,安装目录:D:\libsvm-3.17
  3. gp460win32,安装目录:D:\gnuplot

2、将D:\libsvm-3.17\tools文件夹下的easy.py和grid.py两个文件复制到D:\libsvm-3.17\Python\目录下

3、用任意编辑器打开新复制过来的这两个文件,做如下修改:

easy.py:

1、头部加入import subprocess

2、配置libsvm、gnuplot相关参数,设置好的内容如下:

if not is_win32: # 这部分不用改动
	svmscale_exe = "../svm-scale"
	svmtrain_exe = "../svm-train"
	svmpredict_exe = "../svm-predict"
	grid_py = "./grid.py"
	gnuplot_exe = "/usr/bin/gnuplot"
else: #这部分需要修改:
    # example for windows
	svmscale_exe = "D:/libsvm-3.17/windows/svm-scale.exe"
	svmtrain_exe = "D:/libsvm-3.17/windows/svm-train.exe"
	svmpredict_exe ="D:/libsvm-3.17/windows/svm-predict.exe"
	gnuplot_exe = "D:/gnuplot/bin/pgnuplot.exe"
	grid_py = "D:/libsvm-3.17/python/grid.py"
3、将程序中所有Popen改为subprocess.Popen, 所有PIPE改为subprocess.PIPE


grid.py:

1、头部加入import subprocess

2、配置libsvm、gnuplot相关参数,设置好的内容如下:

if sys.platform != 'win32': #这部分不用改
			self.svmtrain_pathname = os.path.join(dirname, '../svm-train')
			self.gnuplot_pathname = 'D:/libsvm/gnuplot'
		else: #以下程序段需要改:
			# example for windows
			self.svmtrain_pathname = os.path.join(dirname, r'D:/libsvm-3.17/windows/svm-train.exe')
			# svmtrain_pathname = r'c:\Program Files\libsvm\windows\svm-train.exe'
			self.gnuplot_pathname = r'D:/gnuplot/bin/pgnuplot.exe'
3、将程序中所有Popen改为subprocess.Popen, 所有PIPE改为subprocess.PIPE

4、使用libsvm中自带的数据进行测试

下载官方测试数据集:http://www.csie.ntu.edu.tw/~cjlin/papers/guide/data/,比如可以下载train.1, test.1,将其下载到D:/libsvm-3.17/python/目录下。

使用cmd打开此处,使用命令调用程序进行测试:

D:\libsvm-3.17\python>python easy.py train.1 test.1

执行过程如下:


其间还有会有动态变化的统计图表弹出:




支持向量机源码,可在 www.csie.ntu.edu.tw/~cjlin/libsvm/ 下载到最新版本,该版本是 2013年4月更新的,3.17 版。压缩包里面有源代码和文档。以下摘自前述网站: Introduction LIBSVM is an integrated software for support vector classification, (C-SVC, nu-SVC), regression (epsilon-SVR, nu-SVR) and distribution estimation (one-class SVM). It supports multi-class classification. Since version 2.8, it implements an SMO-type algorithm proposed in this paper: R.-E. Fan, P.-H. Chen, and C.-J. Lin. Working set selection using second order information for training SVM. Journal of Machine Learning Research 6, 1889-1918, 2005. You can also find a pseudo code there. (how to cite LIBSVM) Our goal is to help users from other fields to easily use SVM as a tool. LIBSVM provides a simple interface where users can easily link it with their own programs. Main features of LIBSVM include Different SVM formulations Efficient multi-class classification Cross validation for model selection Probability estimates Various kernels (including precomputed kernel matrix) Weighted SVM for unbalanced data Both C++ and Java sources GUI demonstrating SVM classification and regression Python, R, MATLAB, Perl, Ruby, Weka, Common LISP, CLISP, Haskell, OCaml, LabVIEW, and PHP interfaces. C# .NET code and CUDA extension is available. It's also included in some data mining environments: RapidMiner, PCP, and LIONsolver. Automatic model selection which can generate contour of cross valiation accuracy.
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值