找回密码
 注册
关于网站域名变更的通知
查看: 448|回复: 1
打印 上一主题 下一主题

Malab安装libsvm时会遇到的一些坑

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2020-3-9 10:44 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式

EDA365欢迎您登录!

您需要 登录 才可以下载或查看,没有帐号?注册

x
7 C3 h2 o6 m2 R: x3 d+ B+ E" @
工作环境
' t% ]3 Z2 y0 u5 G! [; D
  • 软件环境:Windows 7 Ultimate sp1、MatlabR2012b 32bit
    ! z$ P8 g% e0 Y1 X! [6 ]6 g

  w% y) d& q) W( r! Q今天在使用matlab实现svm算法的时候,发现使用svmtrain函数报错:$ V; A9 ]0 ?& W/ A" ]* ~
Y must be a vector or a character array# S1 `& O5 S- B6 N3 m0 S
立马help svmtrain看看是否少什么东西,命令执行结果如下:
$ Z; Q; v( t7 M0 x
6 q- j5 Y! E0 N' q) U7 X8 Q* t0 ]9 m! ~
  • 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.
  •     ........; k4 t$ P, }3 Y& ?0 c, W/ Y
于是,网上找找资料,这一找不得了,发现大问题!按照参考文献的思路,应该是我的Matlab少了libsvm库,搞不好这个问题无解。幸好libsvm不是matlab自带的,而是需要下载编译的,需要的朋友可以从这https://www.csie.ntu.edu.tw/~cjlin/libsvm/下载。
/ F( W3 W0 S. R4 O! r6 e: ^
$ S  [$ k$ Z* w) Y( z- C" J 2 `. f7 W% U0 h! o) R( \' z. y

# `! V; e8 J6 V6 @1 i/ \- e+ x" m文件内容如下:* k- F( G% K8 E% x; i

. b" S& w$ ?3 w
* o& |" q" A$ b
  _$ P1 p7 L& {* N* }下载下来的是源代码,需要经过编译,查看README.md,可以发现:
9 i3 o5 b# I  L! h: q  t/ V. Y5 k; A6 y: `/ K# U0 |
  • 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.
    * ?, Y, I# d8 M+ {+ J
    ! D6 }8 j/ a7 e
于是赶紧将libsvm压缩包扔到matlab/toolbox/下面,然后定位到libsvm3.23文件夹,输入mex -setup,
5 e# m3 Y" ^6 Q9 B% b( C
( O8 u0 \  E( S9 ]: _0 \3 g5 h
  • 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: Q4 _8 w- ]0 U4 o
   
6 L9 X6 _+ d0 h& K) P+ ?% m: b6 c只有一个编译器!也就是matlab自带的编译器,于是只能选择该编译器,输入make,出来一堆错误:
; V$ H! L: o$ F$ k9 Q- k
5 R( A; o6 L2 `8 m; U4 n9 F
  • >> 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.
    " E& |, S: P9 L1 ]/ `7 s1 u
  ) I; D5 J# i/ g/ @* \. V
原因是lcc 编译器不支持c++,要使得matlab能够编译c++文件的话,只能安装第三方编译器比如微软的vsstudio或者vc++6.0以及mingw-w64,由于vs或者vc比较大我就没再折腾,倒是下载了mingw-w64的离线版,(在线安装版本下载不下来),但是离线版下载下来之后解压缩,死活都配置不好,matlab中就是不显示该编译器!我电脑中其实也有一个cl编译器也不了解如何去配置。最后无果,只能找一个编译好的libsvm32位版本,据说是在winxp下面编译的,通用性应该不错,试了试,可以成功运行!+ O* f$ d1 w, \( a' f( W
5 @$ X- `5 A! w, D6 o  V( P3 V1 B" _0 I$ i

3 ~( J% Z7 n" I) \, w# o, i7 I* A4 }, F

该用户从未签到

2#
发表于 2020-3-9 17:32 | 只看该作者
Malab安装libsvm时的一些坑
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

推荐内容上一条 /1 下一条

EDA365公众号

关于我们|手机版|EDA365电子论坛网 ( 粤ICP备18020198号-1 )

GMT+8, 2025-11-2 00:36 , Processed in 0.156250 second(s), 27 queries , Gzip On.

深圳市墨知创新科技有限公司

地址:深圳市南山区科技生态园2栋A座805 电话:19926409050

快速回复 返回顶部 返回列表