Ubuntu16.04 Matlab2015+LIBSVM

下载

libsvm下载地址:LIBSM下载,下载libsvm-3.23.tar.gz文件,解压缩,将解压好的文件剪贴到安装好的matlab/toolbox下,例如我的路径是:

/usr/local/MATLAB/R2015b/toolbox

编译安装

在libsvm-3.23所在目录/usr/local/MATLAB/R2015b/toolbox打开终端:

sudo chmod 777 libsvm-3.23
cd libsvm-3.23
make

可以使用./svm-train heart_scale来训练进行检验,会输出如下,并生成heart_scale.model文件:

optimization finished, #iter = 162
nu = 0.431029
obj = -100.877288, rho = 0.424462
nSV = 132, nBSV = 107
Total nSV = 132

接着进行预测:./svm-predict heart_scale heart_scale.model heart_scale.out(其中heart_scale为test file, heart_scale.model是由svm-train训练出来对模型文件,heart_scale.out为预测输出文件),会输出如下,并生成heart_scale.out文件:

Accuracy = 86.6667% (234/270) (classification)

编译完成

与Matlab接口的实现

进入/usr/local/MATLAB/R2015b/toolbox/libsvm-3.23/matlab中,打开终端,make一下

错误一

这个部分忘记截图,错误大概就是mexext not found,主要是想说在libsvm-3.23/matlab中有一个README,里面有写到:
在这里插入图片描述
翻译:

在Unix系统上,如果make.m和“mex-setup”都不起作用,请使用Makefile并在命令窗口中键入“make”。
请注意,我们假设您的MATLAB安装在'/usr/local/MATLAB'中。
如果没有,请更换Makefile中的MATLABDIR。

请注意,我们假设您的MATLAB安装在’/usr/local/MATLAB’中。如果没有,请更换Makefile中的MATLABDIR。

  • 原始的Makefile文件中
    在这里插入图片描述

而我的Matlab并不是这个安装路径,所以需要更改为自己的MATLAB路径,如下:
在这里插入图片描述

错误二

在这里插入图片描述问题:
/usr/local/MATLAB/R2015b/bin/glnxa64/mex: /usr/local/MATLAB/R2015b/bin/glnxa64/libtiff.so.5: no version information available (required by /usr/lib/x86_64-linux-gnu/libopencv_highgui.so.2.4)

libopencv_highgui.so.2.4需要调用 /usr/local/MATLAB/R2015b/bin/glnxa64/libtiff.so.5:。但该版本与libopencv_highgui.so.2.4所能用的版本不对应

  • 解决方法:
sudo rm -rf /usr/local/MATLAB/R2015b/bin/glnxa64/libtiff.so.5
 sudo ln -s /usr/lib/x86_64-linux-gnu/libtiff.so.5.2.4 /usr/local/MATLAB/R2015b/bin/glnxa64/libtiff.so.5

linux下Matlab调用及库链接问题no version information available

再重新make一下


/usr/local/MATLAB/R2015b/bin/mex CC="g++" CXX="g++" CFLAGS="-Wall -Wconversion -O3 -fPIC -I/usr/local/MATLAB/R2015b/extern/include -I.." CXXFLAGS="-Wall -Wconversion -O3 -fPIC -I/usr/local/MATLAB/R2015b/extern/include -I.." -largeArrayDims svmpredict.c ../svm.o svm_model_matlab.o
Building with 'gcc'.
Warning: You are using gcc version '5.4.0'. The version of gcc is not supported. The version currently supported with MEX is '4.7.x'. For a list of currently supported compilers see: http://www.mathworks.com/support/compilers/current_release.
Warning: You are using gcc version '5.4.0-6ubuntu1~16.04.12)'. The version of gcc is not supported. The version currently supported with MEX is '4.7.x'. For a list of currently supported compilers see: http://www.mathworks.com/support/compilers/current_release.
/usr/local/MATLAB/R2015b/toolbox/libsvm-3.23/matlab/svmpredict.c: In function ‘int print_null(const char*, ...)’:
/usr/local/MATLAB/R2015b/toolbox/libsvm-3.23/matlab/svmpredict.c:17:36: warning: no return statement in function returning non-void [-Wreturn-type]
 int print_null(const char *s,...) {}
                                    ^

MEX completed successfully.
/usr/local/MATLAB/R2015b/bin/mex CC="g++" CXX="g++" CFLAGS="-Wall -Wconversion -O3 -fPIC -I/usr/local/MATLAB/R2015b/extern/include -I.." CXXFLAGS="-Wall -Wconversion -O3 -fPIC -I/usr/local/MATLAB/R2015b/extern/include -I.." -largeArrayDims svmtrain.c ../svm.o svm_model_matlab.o
Building with 'gcc'.
Warning: You are using gcc version '5.4.0'. The version of gcc is not supported. The version currently supported with MEX is '4.7.x'. For a list of currently supported compilers see: http://www.mathworks.com/support/compilers/current_release.
Warning: You are using gcc version '5.4.0-6ubuntu1~16.04.12)'. The version of gcc is not supported. The version currently supported with MEX is '4.7.x'. For a list of currently supported compilers see: http://www.mathworks.com/support/compilers/current_release.
/usr/local/MATLAB/R2015b/toolbox/libsvm-3.23/matlab/svmtrain.c: In function ‘int read_problem_dense(const mxArray*, const mxArray*)’:
/usr/local/MATLAB/R2015b/toolbox/libsvm-3.23/matlab/svmtrain.c:287:30: warning: conversion to ‘double’ from ‘size_t {aka long unsigned int}’ may alter its value [-Wconversion]
   param.gamma = (double)(1.0/max_index);
                              ^
/usr/local/MATLAB/R2015b/toolbox/libsvm-3.23/matlab/svmtrain.c: In function ‘int read_problem_sparse(const mxArray*, const mxArray*)’:
/usr/local/MATLAB/R2015b/toolbox/libsvm-3.23/matlab/svmtrain.c:370:30: warning: conversion to ‘double’ from ‘size_t {aka long unsigned int}’ may alter its value [-Wconversion]
   param.gamma = (double)(1.0/max_index);
                              ^

MEX completed successfully.
/usr/local/MATLAB/R2015b/bin/mex CC="g++" CXX="g++" CFLAGS="-Wall -Wconversion -O3 -fPIC -I/usr/local/MATLAB/R2015b/extern/include -I.." CXXFLAGS="-Wall -Wconversion -O3 -fPIC -I/usr/local/MATLAB/R2015b/extern/include -I.." -largeArrayDims libsvmread.c
Building with 'gcc'.
Warning: You are using gcc version '5.4.0'. The version of gcc is not supported. The version currently supported with MEX is '4.7.x'. For a list of currently supported compilers see: http://www.mathworks.com/support/compilers/current_release.
Warning: You are using gcc version '5.4.0-6ubuntu1~16.04.12)'. The version of gcc is not supported. The version currently supported with MEX is '4.7.x'. For a list of currently supported compilers see: http://www.mathworks.com/support/compilers/current_release.
MEX completed successfully.
/usr/local/MATLAB/R2015b/bin/mex CC="g++" CXX="g++" CFLAGS="-Wall -Wconversion -O3 -fPIC -I/usr/local/MATLAB/R2015b/extern/include -I.." CXXFLAGS="-Wall -Wconversion -O3 -fPIC -I/usr/local/MATLAB/R2015b/extern/include -I.." -largeArrayDims libsvmwrite.c
Building with 'gcc'.
Warning: You are using gcc version '5.4.0'. The version of gcc is not supported. The version currently supported with MEX is '4.7.x'. For a list of currently supported compilers see: http://www.mathworks.com/support/compilers/current_release.
Warning: You are using gcc version '5.4.0-6ubuntu1~16.04.12)'. The version of gcc is not supported. The version currently supported with MEX is '4.7.x'. For a list of currently supported compilers see: http://www.mathworks.com/support/compilers/current_release.
MEX completed successfully.

添加路径

打开MATLAB,把/usr/local/MATLAB/R2015b/toolbox/libsvm-3.23文件夹路径添加到Matlab的搜索路径(添加并包含子文件夹)
将Matlab的路径设置在/usr/local/MATLAB/R2015b/toolbox/libsvm-3.23下,输入如下测试代码:

[heart_scale_label,heart_scale_inst]=libsvmread('heart_scale');
model = svmtrain(heart_scale_label, heart_scale_inst, '-c 1 -g 0.07');
[predict_label, accuracy, dec_values] =svmpredict(heart_scale_label, heart_scale_inst, model); % test the traindata

显示如下:
在这里插入图片描述完成。

参考:
SVM学习笔记(2):Ubuntu下LibSVM的安装及与Python和Matlab接口的实现

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值