在matlab
上使用libsvm
工具箱使用错误及解决方法汇总
首先附上使用过程
step1:
输入
>>mex -setup
step2: Please choose yourcompiler 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 C2.4.1 in E:\PROGRA~1\MATLAB\R2010a\sys\lcc [2] MicrosoftVisual C++ 2008 SP1 in e:\Program Files\Microsoft Visual Studio 9.0 [3] MicrosoftVisual 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 thesecorrect [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 -g0.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
,搞定了~~~
2
还有一个
make
这一步出现的错误
3 Make
时出错
Undefined function orvariable 'make'
解决方法为:
设置matlab的path
方法file->set path->set subpath(为什么要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 文件添加上即可!
5
到
svmtrain
这一步报错
??? Errorusing ==>svmtrain at 172
Group mustbe a vector.
是因为在添加工具箱的时候没有添加完全,file-Set Path-Add with Subfold ... 添加好路径就可以了
在使用过程中到目前只遇到这些错误~
现在也只是会简单的用libsvm
工具箱……
|