TA的每日心情 | 奋斗 2024-7-1 22:21 |
|---|
签到天数: 2014 天 [LV.Master]伴坛终老
- 自我介绍
- 数学中国站长
群组: 数学建模培训课堂1 群组: 数学中国美赛辅助报名 群组: Matlab讨论组 群组: 2013认证赛A题讨论群组 群组: 2013认证赛C题讨论群组 |
3#
发表于 2014-8-23 22:13
|只看该作者
|
|邮箱已经成功绑定
网上找到这个总结的不错,你可以借鉴!
1 C" N( Z! s0 E) o; z8 K+ c0 j8 p8 P8 z5 R" `$ l' ?; G
在matlab上使用libsvm工具箱使用错误及解决方法汇总
0 ]" {, F- X& V/ c/ K5 Q首先附上使用过程
$ }* X* g( ?: l; Mstep1: 输入>>mex -setup6 L: g1 v, ~9 m
step2:! ]/ q& D6 }0 x0 j1 T
Please choose yourcompiler for building external interface (MEX) files:
* W/ {2 H9 ^; X# k Would you like mex to locate installed compilers [y]/n? 是否让matlab自动检测编译器可以选y
( r0 j; k( I7 L& V, f$ y+ \' ` step3:
# j) s# X1 [8 s; O* T& D/ b Select a compiler:
2 g) a% \6 w* \+ \* p; @6 r
- T4 c8 u% @8 C2 p: l
0 M; S. u4 e( p5 ^ [1] Lcc-win32 C2.4.1 in E:\PROGRA~1\MATLAB\R2010a\sys\lcc / {. K+ C, ]7 y- x- _' g
[2] MicrosoftVisual C++ 2008 SP1 in e:\Program Files\Microsoft Visual Studio 9.0 7 X2 x$ e# [7 A) b$ N
[3] MicrosoftVisual C++ 6.0 in E:\Program Files\Microsoft Visual Studio
: g/ b F5 k, |( C B8 S [0] None ) q7 B: ?8 t$ _* M# X4 S
[1]matlab 自带的不能用 其他的如果有的话 就相应的选择就行 . z$ m- m6 L% V5 M. O1 }$ v9 M
我选择了 【2】- |' ^$ u/ i8 r
step4:
; Z' Q5 L, h: a' c1 B Compiler: Microsoft Visual C++ 2008 SP1
2 e* x5 g0 s, V- j Location:e:\Program Files\Microsoft Visual Studio 9.0 " h9 y$ d+ K* i& t/ s
Are thesecorrect [y]/n? 路径是否正确 是的就选y
0 [' q$ i. ]8 P! h' S 如果没有自动检测出来依次的话step2就选【n】就可以,再顺着提示下来。
& ^: V! |0 ~, Q C/ ^Step 5
+ r- {' N- a1 b) S6 A2 fMake0 L! L# K; a( x5 f e+ I" S
后面就是:
- k; v! c7 @5 a- l4 zload heart_scale.mat(此处无分号)
8 Y4 E5 H: h4 c9 h1 }train = heart_scale_inst;
+ h+ f5 w- j" N# w% o2 }9 ptrain_label=heart_scale_label;
4 T2 ]+ D: K5 `! w5 }/ ttest=train;, L( H; e" t& N3 B" }9 d
test_label=train_label;# x; h0 H- b5 z! |: a& [
model=svmtrain(train_label,train,'-c 2 -g0.01');8 O% T1 }0 l+ T" N2 U; O: X
[predict_label,accuracy]=svmpredict(test_label,test,model);: a# o H1 E; `! M0 `
1
. n/ h9 ^8 ~7 n0 t$ w i! Umake这一步报错
8 _3 p6 I+ ?' T" g9 {; `2 a- Q! RError using mex (line 206)
& [% K0 F; H" P3 pUnable to complete successfully.) ~- G2 E; F6 I9 \0 I9 [
Error in make (line 1)
" d, b* ~5 R4 e- w% This make.m is for MATLAB and OCTAVE H* H: f! }; a7 \% H2 f
under Windows, Mac, and Unix
; ^. d2 s& i+ d9 V2 b3 l# d在尝试了许多方法后,竟然是换了低版本的libsvm,搞定了~~~
% t8 D6 i" z2 {
}8 Q: s* @' u2 还有一个make这一步出现的错误3 Make时出错& Z" |6 A( @" S4 U" j1 j: m2 W
Undefined function orvariable 'make'1 b6 u5 R) W- \' }0 g; ?
解决方法为:5 ^% ?+ U$ u; |3 x7 W1 X( m
设置matlab的path ; a1 Q( ]# u9 `( i3 b% [0 W% ~8 D5 P' p
方法file->set path->set subpath(为什么要sub path因为只有这样才能将你要加的文件目录的子文件都加进去,否则只是加了你所要加的那个目录。)
) P/ N- E- T6 P还要记得把current folder 设为matlab所在的路径7 T: [6 f/ b/ g
3 输入load heart_scale.mat;报错) e& O9 s( h) o3 I* G& Z
Error using load
% ?# j7 }. V4 M2 \& B% s0 s6 ^Unable to read file heart_scale.mat;: No
; y* }+ R3 @8 ?; |# v4 X# jsuch file or directory.
# Q- E" f0 o2 ?9 o: T8 X* A5 _这个问题是这样的,不应该有最后那个; 去掉分号就可以了。。。(粗心所致。。。不知道别人会不会像我这样。。。)
3 J. i- }9 b% S" B" Z45 ]) o8 V. F- P1 |7 H( v
load 这一步报错; F) s3 C5 e6 v# q1 r
??? Error using ==>load
3 d' L N) p4 YNumber of columns on line 2 of ASCII file D:\Program# n$ m2 V/ N9 c2 @% F
Files\MATLAB2010\matlab\toolbox\libsvm-3.13\heart_scale
* O9 _5 z& s0 O9 n& J8 Mmust be the same as previous lines.% t5 y7 w) [6 w0 U% U
官方现在不给heart_scale.mat,给的都是VC++下的格式。一些旧版本的工具箱还可以找到mat文件,新版本都没有了。所以load会报错:heart_scalemust be same as previous lines)
) n- E. ?4 |/ p6 R( b0 L- X, k+ ~0 c一种解决方法是:使用给的一个函数,转化数据。此函数为libsvmread()
- O; T$ w. M' j7 b1 D. T使用如下: [label_vector, instance_matrix] =libsvmread('filename');0 o& w3 z+ F- A8 K) O
此处为了跟官方统一名称可以[heart_scale_label,heart_scale_inst] =libsvmread('heart_scale');
* t. G* D7 u" }" ^2 ~# O3 ]注意:由于heart_scale在libsvm-3.11目录下,不是在matlab下,所以直接用libsvmread命令会报错,要买改变当前路径,或者使用[heart_scale_label,heart_scale_inst]=libsvmread('../heart_scale');../代表返回上层路径。
6 @; U% P# O0 Y0 M8 i8 d4 e但是最简单的方法是,找到旧版本工具箱的mat文件添加上即可!6 r7 ^. O m, T) b8 F0 @" `. v
2 ?, L- [' P- Y: C, n& m, V" [
6 f0 c; u3 p2 \3 E/ U- _
1 m: S* B6 C6 C' m5 H' a5 W0 _. U0 v
5 到svmtrain这一步报错
0 w$ j0 a9 K! K, f7 A9 e, S??? Errorusing ==>svmtrain at 172. h% E# z3 r3 g% V; F
Group mustbe a vector.8 R% N8 I% E# o: | U
是因为在添加工具箱的时候没有添加完全,file-Set Path-Add with Subfold ...添加好路径就可以了# L2 M& @( ` ?( E$ t; A! l1 T
在使用过程中到目前只遇到这些错误~现在也只是会简单的用libsvm工具箱…… |
|