matlab中libsvm安装问题.docx
《matlab中libsvm安装问题.docx》由会员分享,可在线阅读,更多相关《matlab中libsvm安装问题.docx(18页珍藏版)》请在冰豆网上搜索。
matlab中libsvm安装问题
MATLAB中libsvm的安装问题
这个问题折磨了我好久,终于把问题解决了,我把解决方法给大家参考一下,少走些弯路。
我电脑是win7系统,matlab版本是matlab7.1,编译器是用的VC++6.0
现在好多人都用MATLABR2010等版本,这个版本比7.0,7.1要高级,编译器用的版本也比VC6高级,例如VC2008,VC2010,VS2008等,网上libsvm的安装教程一般都是比较高级的版本,所以我要安装的话借鉴那些安装教程出现了很多问题。
首先VC++6.0要用英文版,英文版下载网址网上有很多,也有很多教程,XX经验写的比较详细。
重要的是libsvm的版本问题,因为我的matlab版本较低,因此要选用低版本的libsvm,我用的是libsvm-mat-2.83-1.版本高的可以用比较高级的版本3.14等(我之前就是用的比较高级的版本,因此出现了很多问题,这是最折磨我的)
安装libsvm:
将libsvm-mat-2.83-1解压到你MATLAB中的toolbox中,可以将文件直接命名为libsvm-mat-2.83-1。
我的路径是C:
\ProgramFiles\MATLAB71\toolbox\libsvm-mat-2.83-1。
然后打开matlabfile->setpath->AddwithSubfolders…->找到libsvm-mat-2.83-1的位置点击->save->close
之后第一步:
在commandwindows窗口输入mex–setup
Pleasechooseyourcompilerforbuildingexternalinterface(MEX)files:
Wouldyoulikemextolocateinstalledcompilers[y]/n?
y
Selectacompiler:
[1]DigitalVisualFortranversion6.0inC:
\ProgramFiles\MicrosoftVisualStudio
[2]LccCversion2.4.1inC:
\PROGRAMFILES\MATLAB71\sys\lcc
[3]MicrosoftVisualC/C++version6.0inC:
\ProgramFiles\MicrosoftVisualStudio
[0]None
Compiler:
3(这个要选你在电脑上安装的VC++6.0英文版)
Pleaseverifyyourchoices:
Compiler:
MicrosoftVisualC/C++6.0
Location:
C:
\ProgramFiles\MicrosoftVisualStudio
Arethesecorrect?
([y]/n):
y
Trytoupdateoptionsfile:
C:
\Users\Administrator.PC--20120304RDG\ApplicationData\MathWorks\MATLAB\R14SP3\mexopts.bat
Fromtemplate:
C:
\PROGRAMFILES\MATLAB71\BIN\win32\mexopts\msvc60opts.bat
Done...
***************************************************************************
Warning:
Thefileextensionof32-bitWindowsMEX-fileswaschanged
from".dll"to".mexw32"inMATLAB7.1(R14SP3).Thegenerated
MEX-filewillnotbefoundbyMATLABversionspriorto7.1.
Usethe-outputoptionwiththe".dll"fileextensionto
generateaMEX-filethatcanbecalledinpreviousversions.
Formoreinformationsee:
MATLAB7.1ReleaseNotes,NewFileExtensionforMEX-FilesonWindows
***************************************************************************
Warning可以不用管,出现这些第一步已成功。
(因为我MATLAB版本较低,所以会是这种Warning,比较高级的版本warning不一样)
第二步:
输入make(输入之前要把currentDirectory路径调整到C:
\ProgramFiles\MATLAB71\toolbox\libsvm-mat-2.83-1,如果是libsvm不同,要看limsvmread.c的文件在哪,以libsvmz3.14为例,libsvmread.c是在libsvm3.14\matlab下,所以调整路径到C:
\ProgramFiles\MATLAB71\toolbox\libsvm3.14\matlab)
运行后:
Warning:
Renaming"svmtrain.dll"to"svmtrain.dll.old"toavoidnameconflicts.
***************************************************************************
Warning:
Thefileextensionof32-bitWindowsMEX-fileswaschanged
from".dll"to".mexw32"inMATLAB7.1(R14SP3).Thegenerated
MEX-filewillnotbefoundbyMATLABversionspriorto7.1.
Usethe-outputoptionwiththe".dll"fileextensionto
generateaMEX-filethatcanbecalledinpreviousversions.
Formoreinformationsee:
MATLAB7.1ReleaseNotes,NewFileExtensionforMEX-FilesonWindows
***************************************************************************
Warning:
Renaming"svmpredict.dll"to"svmpredict.dll.old"toavoidnameconflicts.
***************************************************************************
Warning:
Thefileextensionof32-bitWindowsMEX-fileswaschanged
from".dll"to".mexw32"inMATLAB7.1(R14SP3).Thegenerated
MEX-filewillnotbefoundbyMATLABversionspriorto7.1.
Usethe-outputoptionwiththe".dll"fileextensionto
generateaMEX-filethatcanbecalledinpreviousversions.
Formoreinformationsee:
MATLAB7.1ReleaseNotes,NewFileExtensionforMEX-FilesonWindows
***************************************************************************
Warning:
Renaming"read_sparse.dll"to"read_sparse.dll.old"toavoidnameconflicts.
***************************************************************************
Warning:
Thefileextensionof32-bitWindowsMEX-fileswaschanged
from".dll"to".mexw32"inMATLAB7.1(R14SP3).Thegenerated
MEX-filewillnotbefoundbyMATLABversionspriorto7.1.
Usethe-outputoptionwiththe".dll"fileextensionto
generateaMEX-filethatcanbecalledinpreviousversions.
Formoreinformationsee:
MATLAB7.1ReleaseNotes,NewFileExtensionforMEX-FilesonWindows
第二步成功。
第三步验证:
>>loadheart_scale
>>model=svmtrain(heart_scale_label,heart_scale_inst)
model=
Parameters:
[5x1double]
nr_class:
2
totalSV:
132
rho:
0.4245
Label:
[2x1double]
ProbA:
[]
ProbB:
[]
nSV:
[2x1double]
sv_coef:
[132x1double]
SVs:
[132x13double]
>>[predict_label,accuracy]=svmpredict(heart_scale_label,heart_scale_inst,model)
Accuracy=86.6667%(234/270)(classification)
Meansquarederror=0.533333(regression)
Squaredcorrelationcoefficient=0.532639(regression)
predict_label=
1
-1
-1
1
-1
-1
1
1
1
1
1
1
-1
-1
-1
-1
1
1
-1
-1
1
-1
-1
-1
-1
-1
-1
-1
1
-1
1
1
-1
1
1
1
1
-1
-1
-1
-1
-1
-1
-1
-1
-1
1
-1
1
1
1
-1
-1
-1
-1
-1
1
-1
-1
1
-1
1
-1
-1
-1
1
-1
-1
-1
-1
1
-1
-1
-1
-1
1
1
-1
-1
-1
1
1
1
-1
1
-1
-1
-1
-1
1
-1
-1
1
1
1
1
-1
1
-1
-1
-1
-1
-1
1
1
1
-1
1
1
-1
1
-1
-1
-1
-1
-1
1
1
-1
1
1
1
1
-1
-1
-1
1
-1
-1
1
1
1
-1
1
1
-1
-1
1
-1
1
1
-1
1
-1
1
1
-1
1
1
-1
-1
-1
-1
-1
-1
-1
1
-1
-1
1
-1
-1
-1
1
-1
-1
-1
-1
-1
-1
-1
1
1
-1
-1
1
1
-1
1
-1
-1
1
1
-1
-1
-1
1
1
-1
1
-1
1
-1
1
-1
-1
-1
-1
-1
1
-1
1
1
1
1
-1
-1
1
1
-1
-1
-1
-1
1
-1
-1
-1
1
1
-1
1
1
-1
1
-1
-1
1
1
-1
-1
1
1
-1
1
1
1
-1
1
-1
-1
1
-1
-1
1
-1
1
1
-1
-1
1
1
-1
-1
-1
-1
-1
-1
1
-1
-1
-1
1
-1
-1
-1
-1
-1
-1
-1
1
accuracy=
86.6667
0.5333
0.5326
下面说下大家可能会遇到的问题:
问题一:
输入make之前没调整路径,错误:
Warning:
argeArrayDimsspecifiedwith-loptionnotfoundon-Lpath
C:
\PROGRAMFILES\MATLAB71\BIN\MEX.PL:
Error:
'libsvmread.c'notfound.
调整libsvmread.c所在的路径即可,详细请看上面。
问题二:
安装的libsvm较高,错误:
Warning:
argeArrayDimsspecifiedwith-loptionnotfoundon-Lpath
libsvmread.c
libsvmread.c(63):
errorC2065:
'mwIndex':
undeclaredidentifier
libsvmread.c(63):
errorC2065:
'ir':
undeclaredidentifier
libsvmread.c(63):
errorC2065:
'jc':
undeclaredidentifier
libsvmread.c(63):
errorC2100:
illegalindirection
libsvmread.c(64):
errorC2143:
syntaxerror:
missing';'before'type'
libsvmread.c(121):
errorC2065:
'labels':
undeclaredidentifier
libsvmread.c(121):
warningC4047:
'=':
'int'differsinlevelsofindirectionfrom'double*'
libsvmread.c(122):
errorC2065:
'samples':
undeclaredidentifier
libsvmread.c(122):
warningC4047:
'=':
'int'differsinlevelsofindirectionfrom'double*'
libsvmread.c(123):
warningC4047:
'=':
'int'differsinlevelsofindirectionfrom'int*'
libsvmread.c(124):
warningC4047:
'=':
'int'differsinlevelsofindirectionfrom'int*'
libsvmread.c(130):
errorC2109:
subscriptrequiresarrayorpointertype
libsvmread.c(130):
errorC2106:
'=':
leftoperandmustbel-value
libsvmread.c(141):
errorC2109:
subscriptrequiresarrayorpointertype
libsvmread.c(141):
warningC4244:
'=':
conversionfrom'double'to'int',possiblelossofdata
libsvmread.c(141):
errorC2106:
'=':
leftoperandmustbel-value
libsvmread.c(157):
errorC2109:
subscriptrequiresarrayorpointertype
libsvmread.c(157):
errorC2064:
termdoesnotevaluatetoafunction
libsvmread.c(160):
errorC2109:
subscriptrequiresarrayorpointertype
libsvmread.c(160):
warningC4244:
'=':
conversionfrom'double'to'int',possiblelossofdata
libsvmread.c(160):
errorC2106:
'=':
leftoperandmustbel-value
libsvmread.c(170):
errorC2109:
subscriptrequiresarrayorpointertype
libsvmread.c(170):
errorC2106:
'=':
leftoperandmustbel-value
C:
\PROGRAMFILES\MATLAB71\BIN\MEX.PL:
Error:
Compileof'libsvmread.c'failed.
Ifmake.mfails,pleasecheckREADMEaboutdetailedinstructions.
安装较低版本的libsvm即可,建议libsvm-mat-2.83-1
问题三:
VC++6.0是中文版,也可能出现
C:
\PROGRAMFILES\MATLAB71\BIN\MEX.PL:
Error:
Compileof'libsvmread.c'failed.即与问题二相似的问题,这是别人遇到的问题,给大家说下。
目前就是这些问题,希望会对大家有帮助
Libsvm-mat-2.83-1下载地址:
VC++6.0英文版安装教程:
VC++6.0英文版下载地址: