TA的每日心情 | 奋斗 2024-7-1 22:21 |
|---|
签到天数: 2014 天 [LV.Master]伴坛终老
- 自我介绍
- 数学中国站长
群组: 数学建模培训课堂1 群组: 数学中国美赛辅助报名 群组: Matlab讨论组 群组: 2013认证赛A题讨论群组 群组: 2013认证赛C题讨论群组 |
3#
发表于 2014-8-23 22:13
|只看该作者
|
|邮箱已经成功绑定
网上找到这个总结的不错,你可以借鉴!/ k# _# `5 K4 a( k0 O$ o' i
4 W2 N1 ~! p) S6 P1 c( N
在matlab上使用libsvm工具箱使用错误及解决方法汇总
: \: D3 T6 m" w2 j4 D4 ~首先附上使用过程7 W! }" y6 |4 N2 g
step1: 输入>>mex -setup
- \: A, s( F& `+ k: W8 J+ e step2:
( [6 A" T6 w/ u( z/ J% i" r8 } Please choose yourcompiler for building external interface (MEX) files:
- o; t* f4 p* N% O9 [2 d8 L Would you like mex to locate installed compilers [y]/n? 是否让matlab自动检测编译器可以选y
4 x/ I( H p0 R p3 n5 O% K step3:
( [7 E, q# {% O$ f( h Select a compiler:) S6 k/ |6 C+ _: U- x4 U1 k
$ J3 }% [6 q* a, @ [
+ Z/ N) F/ n: F1 ?( H+ w1 x
[1] Lcc-win32 C2.4.1 in E:\PROGRA~1\MATLAB\R2010a\sys\lcc 7 s# k. B1 K, H- k
[2] MicrosoftVisual C++ 2008 SP1 in e:\Program Files\Microsoft Visual Studio 9.0
& d$ P9 ]4 v/ R" G$ q6 Z* f! w [3] MicrosoftVisual C++ 6.0 in E:\Program Files\Microsoft Visual Studio % M7 @/ E: u; b$ e/ V) L/ i+ x& t
[0] None
, G6 H+ h) Z7 l, ^ [1]matlab 自带的不能用 其他的如果有的话 就相应的选择就行
2 N) a9 y. g/ ~. ?3 `: J7 D" m- _5 e2 J 我选择了 【2】
+ C) n( z& M4 i9 s: ]0 y! \ step4:2 y) N- n* }+ a$ S5 t$ x
Compiler: Microsoft Visual C++ 2008 SP1 . e) Q8 }3 x) S) g
Location:e:\Program Files\Microsoft Visual Studio 9.0 : z7 K. G# ^* y3 {
Are thesecorrect [y]/n? 路径是否正确 是的就选y
' F5 k0 @4 S% \/ R+ S0 x$ R" z6 h4 j 如果没有自动检测出来依次的话step2就选【n】就可以,再顺着提示下来。2 f: v# i; E6 \7 _' @
Step 5 : O: P, H2 f9 |, E
Make
- G3 r+ o. t d5 I% Z: b- r% q后面就是:
* q; e: J } J/ M" eload heart_scale.mat(此处无分号)
5 K9 {6 b( A O% Y* Strain = heart_scale_inst;
$ q4 s1 J* J" U3 @train_label=heart_scale_label;. E& [0 R# w- W& K2 U
test=train;
$ @- A9 I' J9 d6 P9 W2 [; t7 O, btest_label=train_label;: Q; t1 U& B z+ E5 _
model=svmtrain(train_label,train,'-c 2 -g0.01');% \$ t m7 {. Z8 ~1 J9 X
[predict_label,accuracy]=svmpredict(test_label,test,model);1 `( i+ r/ \! N$ L4 L9 g
1
/ Y: N$ Z: Y% x& Mmake这一步报错
8 Q" U: `8 \8 w$ F7 i# ~+ y5 y3 ZError using mex (line 206)
+ w* e& s( z4 q d% B3 u% IUnable to complete successfully.6 e: C& u$ r5 v
Error in make (line 1)0 Q3 v" P+ l5 u6 ?. ?
% This make.m is for MATLAB and OCTAVE
& h! p$ L* p/ f- m2 [' N x' nunder Windows, Mac, and Unix4 c5 I2 ~& H7 w: F6 j W( L
在尝试了许多方法后,竟然是换了低版本的libsvm,搞定了~~~+ t" g9 m6 M0 |9 {1 v
1 ~# H4 ~5 M3 r
2 还有一个make这一步出现的错误3 Make时出错5 F% N0 Q( f. `% g
Undefined function orvariable 'make'
$ J* r; ^/ L( q. M, D解决方法为:
* q$ `' O ^, H设置matlab的path
, K2 k$ C5 G$ \ 方法file->set path->set subpath(为什么要sub path因为只有这样才能将你要加的文件目录的子文件都加进去,否则只是加了你所要加的那个目录。)/ Y8 s9 X4 I( h i: z
还要记得把current folder 设为matlab所在的路径
# c6 s) I7 i( w# K8 m3 输入load heart_scale.mat;报错
& r2 k D* o6 ^9 Z, vError using load$ d! P$ T# ]7 \* r; T( c
Unable to read file heart_scale.mat;: No
4 r2 U" y I& L$ G( `such file or directory./ j, W j5 R+ l& P k2 a
这个问题是这样的,不应该有最后那个; 去掉分号就可以了。。。(粗心所致。。。不知道别人会不会像我这样。。。)
' ]7 U5 p8 q' ]' s0 t* a4 q9 H o( T6 C" I9 @+ _
load 这一步报错
' K0 k) _$ z* O" E??? Error using ==>load$ |% C" l& r, m$ N; t5 m- q
Number of columns on line 2 of ASCII file D:\Program$ \0 h1 s" ?" P4 s% `3 q
Files\MATLAB2010\matlab\toolbox\libsvm-3.13\heart_scale
$ T) s" {( m `' H9 omust be the same as previous lines.
N) R0 X2 h7 h/ `: \官方现在不给heart_scale.mat,给的都是VC++下的格式。一些旧版本的工具箱还可以找到mat文件,新版本都没有了。所以load会报错:heart_scalemust be same as previous lines)5 W& I, G6 H# n
一种解决方法是:使用给的一个函数,转化数据。此函数为libsvmread()1 `+ ]! N5 m0 P0 u* }6 x
使用如下: [label_vector, instance_matrix] =libsvmread('filename');2 W: Y/ C2 m% A# X/ ]# |# F6 x
此处为了跟官方统一名称可以[heart_scale_label,heart_scale_inst] =libsvmread('heart_scale');
7 c: w$ ^5 {1 E& L+ ^& D/ K* E注意:由于heart_scale在libsvm-3.11目录下,不是在matlab下,所以直接用libsvmread命令会报错,要买改变当前路径,或者使用[heart_scale_label,heart_scale_inst]=libsvmread('../heart_scale');../代表返回上层路径。
0 ]7 G: ]/ t0 d4 Z* D/ x但是最简单的方法是,找到旧版本工具箱的mat文件添加上即可!
$ H/ H) ~# a8 Q5 B; T7 m
+ O' f- I" n$ Z* h* I( D/ y; o( F0 ^+ g
! A- g% X! g2 e' F8 p; ~( H# @1 N
( f" _$ O& M7 c4 r7 `3 \
5 到svmtrain这一步报错0 D { F% y; W/ |' |
??? Errorusing ==>svmtrain at 1729 V9 Y, H) _% M: N
Group mustbe a vector.* O6 C7 `9 i# p
是因为在添加工具箱的时候没有添加完全,file-Set Path-Add with Subfold ...添加好路径就可以了# T( Q) R1 m) w- r
在使用过程中到目前只遇到这些错误~现在也只是会简单的用libsvm工具箱…… |
|