当前位置:网站首页>MATLAB R2021b 安装libsvm
MATLAB R2021b 安装libsvm
2022-07-07 23:31:00 【dgdqqxxx】
MATLAB R2021b 安装libsvm
前言
处理器:AMD Ryzen 9 5950X 16-Core Processor 3.40 GHz
操作系统:Windows 10 专业版
版本号:21H1
内部版本:19043.1645
MATLAB版本:2021b
一、下载安装libsvm
1、下载libsvm
libsvm官网:https://www.csie.ntu.edu.tw/~cjlin/libsvm
我当时点了前两个下载链接没反应,最后点的github连接下载的
2、解压libsvm
将下载的压缩包解压然后复制到MATLAB安装目录的toolbox下
3、设置MATLAB路径
点添加并包含子文件夹,选择刚才的libsvm-master文件夹,点确定后会自动将下面的子文件夹也添加进来
4、编译可能遇到的问题
在matlab命令行中输入mex -setup -v 查看一下电脑中有啥编译器
结果啥都没有
根据谦恭的博客:https://blog.csdn.net/github_35807147/article/details/80725642
安装以MinGW64 Compiler (C++)为例:
1.首先下载并且安装TDM-GCC:
http://tdm-gcc.tdragon.net/download
2.最好安装在C盘根目录下,目录中不要有空格,安装时默认勾选Add to PATH,就不需要后面再配环境变量
3.在MATLAB的命令行中敲入命令:
setenv(‘MW_MINGW64_LOC’,‘C:\TDM-GCC-64’)
此时再运行前面的那句
mex -setup -v
就可以看到下图结果,编译器已经有了
5、编译
将MATLAB的当前文件夹切换到libsvm-master/matlab目录:
输入make并运行
出现了很多警告但也多了四个文件,应该是编译成功了
二、测试
将Libsvm-master文件夹下的测试数据集heart_scale复制到Libsvm\matlab下,后续的操作将在该文件夹下进行,同时将MATLAB工作路径转至该文件下
然后输入:
[heart_scale_label,heart_scale_inst]=libsvmread('heart_scale');
model = svmtrain(heart_scale_label,heart_scale_inst) ;
[predict_label,accuracy,dec_values] = svmpredict(heart_scale_label,heart_scale_inst,model);
得到结果如下,应该是安装成功了
三、使用小技巧
1、libsvm标准格式转换工具
libsvm的数据集格式是:
标签 1:特征值1 2:特征值2…
可以借助excel实现标准格式转换,百度网盘链接如下:
http://pan.baidu.com/s/1eSKebYU
DADADA开飞机的DATA的简书地址:LIBSVM之svm-train
excel里点击菜单栏视图,宏——查看宏
点击FormatDataFromLibsvm,执行,就会将数据转换为标签在最后一列的格式,如下图所示:
点击FormatDataToLibsvm就会将数据转换为libsvm的标准格式,如下图所示:
转换完后可以将excel的内容另存为txt文件(excel另存为有俩种txt格式,建议使用文本文件(制表格分割))
2、数据归一化
SVM对数据大小是敏感的,一般都需要先将特征进行归一化,如缩放到(0,1)区间,在libsvm-3.23\windows文件夹有一个svm-scale.exe 的执行程序,该exe文件双击无法使用。需要在windows cmd 里运行(按住windows+R,输入cmd即可)
将转换好的txt文本复制到该目录,将cmd里路径调至该文件夹(可将文件夹直接拖入cmd,手动输太xxx的长了);
也可在windows文件夹下按住shift,右键,在此处打开powershell窗口,则路径自动在当前目录下:
输入.\svm-scale.exe .\a.txt > a1.txt
大于号前后都有空格
可以看出默认被归一化到了(0,1)区间
3、训练及预测
将归一化好的a1.txt文件复制到libsvm-3.23\matlab 目录下:
[lable,im]=libsvmread('a1.txt'); %读取文件
model=svmtrain(lable(1:8754),im(1:8754,:),'-s 4 -t 2 -c 1 -g 0.125'); %训练(共12505条样本,选前70%作为训练集,即8754)
[prelabel,accuracy,decision_values]=svmpredict(lable(8755:12505),im(8755:12505,:),model); %预测(后30%作为测试集,即8755-12505条)
以上便是svm的简单使用
4、寻找最优参数
需要安装python和gnuplot;我的python版本是3.10;gnuplot下载了目前最新的版本gp543-win64-mingw.exe
gnuplot官网地址: http://www.gnuplot.info/ (就是个画图的工具,画c和g自动寻参的图,默认下一步安装就行,安装完看看和easy.py里第25行的调用路径一致否)
官网:
下载:
检查安装路径是否一致
打开命令行,输入
python .\easy.py .\train.txt .\test.txt
train.txt和test.txt分别存放着训练集和测试集,easy.py后面跟原始的测试集和训练集即可,会自己进行归一化等等操作;运行它则可自动调用svmscale.exe grid.py svmtrain.exe svmpredict.exe ,简单一步到位;会输出bestc和bestg和accuracy等
期间会自动打开gnuplot画图,略卡,画完自己关闭,生成一些中间文件如下图。
寻找最佳参数的过程如下图所示:
参考
MATLAB libsvm 安装和使用
MATLAB安装配置libsvm(附MinGW64配置)
LIBSVM之svm-train
边栏推荐
- Matlab code about cosine similarity
- FIR filter of IQ signal after AD phase discrimination
- qt--将程序打包--不要安装qt-可以直接运行
- Measure the voltage with analog input (taking Arduino as an example, the range is about 1KV)
- Design method and application of ag9311maq and ag9311mcq in USB type-C docking station or converter
- Content of one frame
- qt--將程序打包--不要安裝qt-可以直接運行
- Overall introduction of the project
- How to use education discounts to open Apple Music members for 5 yuan / month and realize member sharing
- High quality USB sound card / audio chip sss1700 | sss1700 design 96 kHz 24 bit sampling rate USB headset microphone scheme | sss1700 Chinese design scheme explanation
猜你喜欢
2022 safety officer-c certificate examination paper and safety officer-c certificate simulated examination question bank
Getting started STM32 -- how to learn stm32
Gnuradio transmits video and displays it in real time using VLC
2021 Shanghai safety officer C certificate examination registration and analysis of Shanghai safety officer C certificate search
Understanding of expectation, variance, covariance and correlation coefficient
2022 safety officer-c certificate examination summary and safety officer-c certificate reexamination examination
Chapter VIII integrated learning
Common configurations in rectangular coordinate system
HDMI to VGA acquisition HD adapter scheme | HDMI to VGA 1080p audio and video converter scheme | cs5210 scheme design explanation
Ag9311maq design 100W USB type C docking station data | ag9311maq is used for 100W USB type C to HDMI with PD fast charging +u3+sd/cf docking station scheme description
随机推荐
2021-04-12 - new features lambda expression and function functional interface programming
Capstone/cs5210 chip | cs5210 design scheme | cs5210 design data
Chapter improvement of clock -- multi-purpose signal modulation generation system based on ambient optical signal detection and custom signal rules
2021 welder (primary) examination skills and welder (primary) operation examination question bank
The usage of rand function in MATLAB
Connect to the previous chapter of the circuit to improve the material draft
Design method and application of ag9311maq and ag9311mcq in USB type-C docking station or converter
Continued from the previous design
Plot function drawing of MATLAB
Blue Bridge Cup embedded (F103) -1 STM32 clock operation and led operation method
Recommend a document management tool Zotero | with tutorials and learning paths
4. Strategic Learning
qt-使用自带的应用框架建立--hello world--使用min GW 32bit
npm 内部拆分模块
USB type-C mobile phone projection scheme | USB type-C docking station scheme | TV / projector type-C converter scheme | ag9300ag9310ag9320
How does Matplotlib generate multiple pictures in turn & only save these pictures without displaying them in the compiler
2021-03-06 - play with the application of reflection in the framework
Apt get error
Solve the error: NPM warn config global ` --global`, `--local` are deprecated Use `--location=global` instead.
2022 safety officer-a certificate free examination questions and safety officer-a certificate mock examination