llibsvm-svdd-3.1的编译make

本文详细介绍SVDD-3.1工具箱在LibSVM-3.1环境下的安装步骤及常见问题解决方法,包括文件替换、路径设置、编译错误修正等关键环节。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

从libsvm官网上的LibSVM Tools(http://www.csie.ntu.edu.tw/~cjlin/libsvmtools/)中下载svdd-3.1工具箱

网站原文说:

LIBSVM for SVDD and finding the smallest sphere containing all data

SVDD is another type of one-class SVM. We implement the formulation in Tax and Duin, Support Vector Data Description, Machine Learning, vol. 54, 2004, 45-66. Please download this zip file, put sources into libsvm-3.1 (http://www.csie.ntu.edu.tw/~cjlin/libsvm/oldfiles/), and make the code. The options are

  • -s 5 SVDD
  • -s 6 gives the square of the radius for L1-SVM
  • -s 7 gives the square of the radius for L2-SVM

 

其中明确强调要把svdd-3.1工具箱放到libsvm-3.1中,注意版本,其他版本会安装错误。

 

[教程] llibsvm-svdd-3.1安装过程详解http://www.matlabsky.com/forum.php?mod=viewthread&tid=35981)中介绍了详细的过程及出现的问题,在此直接copy过来了。原文出现在

liqi3837671的博客“在libsvm中遇到的svdd-3.1程序不能被matlab mex编译的问题 ”(http://liqi3837671.blog.163.com/blog/static/165912886201217101744904/

 


1、下载svdd工具箱(http://www.csie.ntu.edu.tw/~cjlin/libsvmtools/),里面有一个matlab文件夹和3个文件svm.cpp、svm.h、svm-train.c。
2、将matlab文件夹中的文件svm_model_matlab.c、svmtrain.c拷贝到libsvm的matlab文件夹中,会提示文件名相同,是否覆盖,点是。
3、将svm.cpp、svm.h、svm-train.c这3个文件拷贝到libsvm文件夹下,也会有文件名相同,是否覆盖的提示,同样点是。
4、按照faruto版主的帖子libsvm安装方法一文中的要求重新安装libsvm,设置搜索路径、mex -setup、make等等。最关键就在于make后出现的问题
>> make
svmtrain.c 
svmtrain.c(457) : error C2065: 'ptr' : undeclared identifier 
svmtrain.c(457) : warning C4047: '=' : 'int' differs in levels of indirection from 'double *' 
svmtrain.c(458) : error C2065: 'ptr' : undeclared identifier 
svmtrain.c(458) : error C2109: subscript requires array or pointer type 

C:\MATLAB~1\BIN\MEX.PL: Error: Compile of 'svmtrain.c' failed. 会出现这样的提示
5、打开svmtrain.c文件,拖到第455行,相关代码如下:
if(cross_validation)
  {
   
   if(param.svm_type == R2 || param.svm_type == R2q)
   {
    mexPrintf("\"R^2\" cannot do cross validation.\n");
    fake_answer(plhs);
    return;
   }
   double *ptr;
   plhs[0] = mxCreateDoubleMatrix(1, 1, mxREAL);
   ptr = mxGetPr(plhs[0]);
   ptr[0] = do_cross_validation();
  
  }
将double *ptr;放到这段语句的上端,就不能出现上述那个错误:
if(cross_validation)
  {
   double *ptr;
   if(param.svm_type == R2 || param.svm_type == R2q)
   {
    mexPrintf("\"R^2\" cannot do cross validation.\n");
    fake_answer(plhs);
    return;
   }

   plhs[0] = mxCreateDoubleMatrix(1, 1, mxREAL);
   ptr = mxGetPr(plhs[0]);
   ptr[0] = do_cross_validation();
  
  }
6、修改完svmtrain.c文件后,关闭matlab,重新按照步骤4操作,就可正确运行了。
>> load heart_scale;
>> model = svmtrain(heart_scale_label,heart_scale_inst,'-s 5');
*
optimization finished, #iter = 75
radius = 0.750478
obj = -0.315256, rho = -0.096973
nSV = 139, nBSV = 131
>> [predict_label,accuracy] = svmpredict(heart_scale_label,heart_scale_inst,model);
Accuracy = 46.6667% (126/270) (classification)

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值