3 f2 ~' w$ z8 P1 J* I4 b
今天在使用matlab实现svm算法的时候,发现使用svmtrain函数报错:: ~$ y1 h0 `$ |: s3 @
Y must be a vector or a character array 4 c% L" q! e. v4 X" ]8 Z立马help svmtrain看看是否少什么东西,命令执行结果如下:5 k8 Q/ R* W5 F8 y* Q0 j
& H S J5 o; e
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.
........ : d1 k' ^. k. \
于是,网上找找资料,这一找不得了,发现大问题!按照参考文献的思路,应该是我的Matlab少了libsvm库,搞不好这个问题无解。幸好libsvm不是matlab自带的,而是需要下载编译的,需要的朋友可以从这https://www.csie.ntu.edu.tw/~cjlin/libsvm/下载。 , F, R; r' I7 l: o0 ?; f* j5 W- X# o! F' I6 L3 l9 J$ W
=> Please check README for detailed instructions.! ~" j5 g$ t8 v9 s( p$ Y+ L
6 o" o( y9 j. T原因是lcc 编译器不支持c++,要使得matlab能够编译c++文件的话,只能安装第三方编译器比如微软的vsstudio或者vc++6.0以及mingw-w64,由于vs或者vc比较大我就没再折腾,倒是下载了mingw-w64的离线版,(在线安装版本下载不下来),但是离线版下载下来之后解压缩,死活都配置不好,matlab中就是不显示该编译器!我电脑中其实也有一个cl编译器也不了解如何去配置。最后无果,只能找一个编译好的libsvm32位版本,据说是在winxp下面编译的,通用性应该不错,试了试,可以成功运行!8 Q, }* _. S2 T5 H; w. ]
* s/ a2 B+ y. X% E2 @6 J0 v3 z g