经过几天的学习,终于可以正常的用libsvm工具箱咯……工具箱很强大但是刚开始总是错误百出啊!在遇到问题时google了一下在网上总能找到很多解决方法。。。我总结的是能解决我当时的问题的那些~
首先附上使用过程
step1: 输入>>mex -setup
step2:
Please choose your compiler for building external interface (MEX) files:
Would you like mex to locate installed compilers [y]/n? 是否让matlab自动检测编译器 可以选y
step3:
Select a compiler:
[1] Lcc-win32 C 2.4.1 in E:\PROGRA~1\MATLAB\R2010a\sys\lcc
[2] Microsoft Visual C++ 2008 SP1 in e:\Program Files\Microsoft Visual Studio 9.0
[3] Microsoft Visual C++ 6.0 in E:\Program Files\Microsoft Visual Studio
[0] None
[1]matlab 自带的不能用 其他的如果有的话 就相应的选择就行
我选择了 【2】
step4:
Compiler: Microsoft Visual C++ 2008 SP1
Location: e:\Program Files\Microsoft Visual Studio 9.0
Are these correct [y]/n? 路径是否正确 是的就选y
如果没有自动检测出来依次的话step2就选【n】就可以,再顺着提示下来。
Step 5
Make
后面就是:
load heart_scale.mat(此处无分号)
train = heart_scale_inst;
train_label=heart_scale_label;
test=train;
test_label=train_label;
model=svmtrain(train_label,train,'-c 2 -g 0.01');
[predict_label,accuracy]=svmpredict(test_label,test,model);
1
make这一步报错
Error using mex (line 206)
Unable to complete successfully.
Error in make (line 1)
% This make.m is for MATLAB and OCTAVE
under Windows, Mac, and Unix
在尝试了许多方法后,竟然是换了低版本的libsvm,搞定了~~~
另:Libsvm各个版本http://www.csie.ntu.edu.tw/~cjlin/libsvm/matlab/oldfiles/
2 还有一个make这一步出现的错误
Undefined function or variable 'make'
解决方法为:
设置matlab的path
方法file->set path->set sub path(为什么要sub path因为只有这样才能将你要加的文件目录的子文件都加进去,否则只是加了你所要加的那个目录。)
还要记得把current folder 设为matlab所在的路径
3 输入load heart_scale.mat;报错
Error using load
Unable to read file heart_scale.mat;: No
such file or directory.
这个问题是这样的,不应该有最后那个; 去掉分号就可以了。。。(粗心所致。。。不知道别人会不会像我这样。。。)
4
load 这一步报错
??? Error using ==> load
Number of columns on line 2 of ASCII file D:\Program
Files\MATLAB2010\matlab\toolbox\libsvm-3.13\heart_scale
must be the same as previous lines.
官方现在不给heart_scale.mat,给的都是VC++下的格式。一些旧版本的工具箱还可以找到mat文件,新版本都没有了。所以load会报错:heart_scalemust be same as previous lines)
一种解决方法是:使用给的一个函数,转化数据。此函数为libsvmread()
使用如下: [label_vector, instance_matrix] =libsvmread('filename');
此处为了跟官方统一名称可以[heart_scale_label,heart_scale_inst] =libsvmread('heart_scale');
注意:由于heart_scale在libsvm-3.11目录下,不是在matlab下,所以直接用libsvmread命令会报错,要买改变当前路径,或者使用[heart_scale_label,heart_scale_inst] =libsvmread('../heart_scale');../代表返回上层路径。
但是最简单的方法是,找到旧版本工具箱的mat文件添加上即可!
我把需要的mat文件分享在我的网盘中了 http://pan.baidu.com/share/link?shareid=127727&uk=2165237662
5 到svmtrain这一步报错
??? Errorusing ==> svmtrain at 172
Group mustbe a vector.
是因为在添加工具箱的时候没有添加完全,file-Set Path-Add with Subfold ...添加好路径就可以了