|
|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
5 m9 Y/ Y' b& O2 ^) {' ~: @
工作环境
2 S/ U+ ~6 t& R. N( D3 D8 D- 软件环境:Windows 7 Ultimate sp1、MatlabR2012b 32bit. Y5 b% |: H( \0 A
8 C4 R8 X5 o* c2 }% r
今天在使用matlab实现svm算法的时候,发现使用svmtrain函数报错:
0 b: C- R" v: uY must be a vector or a character array
4 e& _2 T, X8 b. G立马help svmtrain看看是否少什么东西,命令执行结果如下:
8 d8 Z$ s- [0 @! B! r' F4 Z3 S4 o7 k+ w
- help svmtrain
- svmtrain Train a support vector machine classifier
- SVMSTRUCT = svmtrain(TRAINING, Y) trains a support vector machine (SVM)
- classifier on data taken from two groups. TRAINING is a numeric matrix
- of predictor data. Rows of TRAINING correspond to observations; columns
- correspond to features. Y is a column vector that contains the known
- class labels for TRAINING. Y is a grouping variable, i.e., it can be a
- categorical, numeric, or logical vector; a cell vector of strings; or a
- character matrix with each row representing a class label (see help for
- groupingvariable). Each element of Y specifies the group the
- corresponding row of TRAINING belongs to. TRAINING and Y must have the
- same number of rows. SVMSTRUCT contains information about the trained
- classifier, including the support vectors, that is used by SVMCLASSIFY
- for classification. svmtrain treats NaNs, empty strings or 'undefined'
- values as missing values and ignores the corresponding rows in
- TRAINING and Y.
- ........# r$ X; b2 G4 W0 O; l
于是,网上找找资料,这一找不得了,发现大问题!按照参考文献的思路,应该是我的Matlab少了libsvm库,搞不好这个问题无解。幸好libsvm不是matlab自带的,而是需要下载编译的,需要的朋友可以从这https://www.csie.ntu.edu.tw/~cjlin/libsvm/下载。) ~5 l% `% k& P/ X, ~$ p0 Z
0 U, U6 ~7 A% w5 R* C2 b
' D* B/ i) J" k9 ~5 V2 g( t
# f' z1 l" b# O, U& B9 s+ f; c3 A
文件内容如下:6 m/ l5 _' F0 m7 a- G6 R
0 K, Q! T8 j' g5 |! a
1 G* F4 E# v# ^9 W$ w& g' c
: c4 x5 i; K. c: Y! X* X下载下来的是源代码,需要经过编译,查看README.md,可以发现:$ h0 J9 q0 J7 O' D+ ]& _3 t' R
3 z A- O+ O+ f" B0 \4 E- `
- Example:
- matlab>> mex -setup
- (ps: MATLAB will show the following messages to setup default compiler.)
- Please choose your compiler for building external inteRFace (MEX) files:
- Would you like mex to locate installed compilers [y]/n? y
- Select a compiler:
- [1] Microsoft Visual C/C++ version 7.1 in C:\Program Files\Microsoft Visual Studio
- [0] None
- Compiler: 1
- Please verify your choices:
- Compiler: Microsoft Visual C/C++ 7.1
- Location: C:\Program Files\Microsoft Visual Studio
- Are these correct?([y]/n): y
- matlab>> make
- On Unix systems, if neither make.m nor 'mex -setup' works, please use
- Makefile and type 'make' in a command window. Note that we assume
- your MATLAB is installed in '/usr/local/matlab'. If not, please change
- MATLABDIR in Makefile.# d7 @3 T7 M" x; x+ U& J% Q
5 {3 }; Z8 n. P/ m4 ~于是赶紧将libsvm压缩包扔到matlab/toolbox/下面,然后定位到libsvm3.23文件夹,输入mex -setup,
: }7 U2 J- W" Y5 ]2 Q$ x
) b; R/ B5 B8 H: b# Y6 y- Select a compiler:
- [1] Lcc-win32 C 2.4.1 in E:\1_PROG~1\MATLAB~1\sys\lcc
- [0] None
- Compiler: mex -setup
- Please select from 0-1
- Compiler:
- Please select from 0-1
- Compiler: 1
- Please verify your choices:
- Compiler: Lcc-win32 C 2.4.1
- Location: E:\1_PROG~1\MATLAB~1\sys\lcc
$ s# H" Y: \! v8 w- x & b4 U1 p0 ]. Y: H
只有一个编译器!也就是matlab自带的编译器,于是只能选择该编译器,输入make,出来一堆错误:% w" d% C6 D0 T! K- [" Y
Y! P) F4 F- d; u& Y
- >> make
- Error ..\svm.cpp: 15 syntax error; found `<' expecting `;'
- Error ..\svm.cpp: 15 skipping `<'
- Error ..\svm.cpp: 15 syntax error; found `T' expecting `;'
- Error ..\svm.cpp: 15 syntax error; found `>' expecting `;'
- Error ..\svm.cpp: 15 skipping `>'
- Error ..\svm.cpp: 15 syntax error; found `T' expecting `;'
- Error ..\svm.cpp: 15 syntax error; found `min' expecting `;'
- Error ..\svm.cpp: 15 syntax error; found `x' expecting `)'
- Error ..\svm.cpp: 15 skipping `x' `,' `T' `y'
- Error ..\svm.cpp: 15 undeclared identifier `x'
- Error ..\svm.cpp: 15 undeclared identifier `y'
- Warning ..\svm.cpp: 15 possible usage of x before definition
- Warning ..\svm.cpp: 15 possible usage of y before definition
- Error ..\svm.cpp: 18 syntax error; found `<' expecting `;'
- Error ..\svm.cpp: 18 skipping `<'
- Error ..\svm.cpp: 18 syntax error; found `T' expecting `;'
- Error ..\svm.cpp: 18 syntax error; found `>' expecting `;'
- Error ..\svm.cpp: 18 skipping `>'
- Error ..\svm.cpp: 18 syntax error; found `T' expecting `;'
- Error ..\svm.cpp: 18 syntax error; found `max' expecting `;'
- Error ..\svm.cpp: 18 syntax error; found `x' expecting `)'
- Error ..\svm.cpp: 18 skipping `x' `,' `T' `y'
- Error ..\svm.cpp: 18 too many errors
- E:\1_PROG~1\MATLAB~1\BIN\MEX.PL: Error: Compile of '..\svm.cpp' failed.
- Error: E:\1_Program_File\MatlabR2012b\toolbox\matlab\general\mex.m failed (line 206)
- Unable to complete successfully.
- => Please check README for detailed instructions.0 Q) r. o+ X, l c0 o) u
3 p! w1 h# K0 H. c4 ]6 v, v原因是lcc 编译器不支持c++,要使得matlab能够编译c++文件的话,只能安装第三方编译器比如微软的vsstudio或者vc++6.0以及mingw-w64,由于vs或者vc比较大我就没再折腾,倒是下载了mingw-w64的离线版,(在线安装版本下载不下来),但是离线版下载下来之后解压缩,死活都配置不好,matlab中就是不显示该编译器!我电脑中其实也有一个cl编译器也不了解如何去配置。最后无果,只能找一个编译好的libsvm32位版本,据说是在winxp下面编译的,通用性应该不错,试了试,可以成功运行!' c8 Y1 `- x* c9 C6 j
y. f- Z+ v% P. T9 K
3 x; A/ D4 L8 [& Z7 S2 Q |
|