当前位置:网站首页>【数据分析】基于MATLAB实现SVDD决策边界可视化
【数据分析】基于MATLAB实现SVDD决策边界可视化
2022-08-03 02:08:00 【matlab_dingdang】
1 内容介绍
在现实世界中,万事万物都有着其特征,这样的特征或多或少、或重要或不重要。人们通过事物的特征可以确定其所属分类,但是当事物的特征都很多时,如果人们依靠传统的方法对事物进行分类就显得耗时耗力,并且分类的精确性不高。而分类作为一种预测模型,如果分类的精确性低或用时长,则这种预测将变得毫无价值。因此人们提出了各种分类模型来对事物进行预测,其中支持向量机和支持向量描述数据在对高维数据进行预测时有着一定的优势,并且根据不同的要求,对这两种算法的改进应用到了现实生活中的许多领域。 首先,本文研究了数据挖掘分类算法中的支持向量机的背景和理论,分析并总结了SVM各种改进方法的研究现状。
2 仿真代码
function x_range = grid_range(x, varargin)
%{
% DESCRIPTION
Compute the range of grid
x_range = grid_range(x)
x_range = grid_range(x, 'r', 0.5)
x_range = grid_range(x, 'n', 200)
x_range = grid_range(x, 'r', 0.5, 'n', 200)
INPUT
x Training inputs (N*1)
N: number of samples
r Radio of expansion (0<r<1)
n Number of grids
OUTPUT
x_range range of grid
Created on 18th October 2019, by Kepeng Qiu.
-------------------------------------------------------------%
%}
% Default Parameters setting
r = 0.5; % radio of expansion (0<r<1)
n = 2*size(x, 1); % number of grids
% Parameters setting
if ~rem(nargin, 2)
error('Parameters to rvm_train should be pairs')
end
numParameters = (nargin-1)/2;
if numParameters ~= 0
for i =1:numParameters
Parameters = varargin{(i-1)*2+1};
value = varargin{(i-1)*2+2};
switch Parameters
%
case 'r'
r = value;
%
case 'n'
n = value;
end
end
end
%
xlim_1 = min(x);
xlim_2 = max(x);
% min
if xlim_1<0
xlim_1 = xlim_1*(1+r);
else
xlim_1 = xlim_1*(1-r);
end
% max
if xlim_2<0
xlim_2 = xlim_2*(1-r);
else
xlim_2 = xlim_2*(1+r);
end
% range of grid
x_range = linspace(xlim_1, xlim_2, n);
end
function [traindata, testdata, trainlabel, testlabel] = prepareData
%{
% DESCRIPTION
Prepare the data for SVDD_WOA
[traindata, testdata, trainlabel, testlabel] = prepareData
OUTPUT
traindata Training data
testdata Testing data
trainlabel Training label
trainlabel Training label
Created on 18th October 2019, by Kepeng Qiu.
-------------------------------------------------------------%
%}
load .\data\banana.mat
traindata(:, 1) = banana(1:2:500, 1);
traindata(:, 2) = banana(1:2:500, 2);
testdata(:, 1) = banana(501:2:1000, 1);
testdata(:, 2) = banana(501:2:1000, 2);
trainlabel = ones(size(traindata, 1), 1);
testlabel = -ones(size(testdata, 1), 1);
end
function [rho, X1, X2] = decision_boundary(model, traindata)
%{
% DESCRIPTION
Computation of decision boundary
[rho, X1, X2] = decision_boundary(model, traindata)
INPUT
model SVDD model
N: number of samples
traindata Training data
OUTPUT
rho Bias term
X1, X2 Grid range
Created on 18th October 2019, by Kepeng Qiu.
-------------------------------------------------------------%
%}
% Compute the range of grid
x1_range = grid_range(traindata(:, 1));
x2_range = grid_range(traindata(:, 2));
% grid
[X1, X2] = meshgrid(x1_range, x2_range);
X_Grid = [X1(:), X2(:)];
% the grid label is only for the input of the function 'libsvmpredict'
grid_label = ones(size(X_Grid, 1), 1);
% Predict the label of each grid point
[~, ~, rho_0] = libsvmpredict(grid_label, X_Grid, model);
rho = reshape(rho_0, size(X1, 1), size(X1, 2));
end
function [traindata, testdata, trainlabel, testlabel] = prepareData
%{
% DESCRIPTION
Prepare the data for SVDD_WOA
[traindata, testdata, trainlabel, testlabel] = prepareData
OUTPUT
traindata Training data
testdata Testing data
trainlabel Training label
trainlabel Training label
Created on 18th October 2019, by Kepeng Qiu.
-------------------------------------------------------------%
%}
load .\data\banana.mat
traindata(:, 1) = banana(1:2:500, 1);
traindata(:, 2) = banana(1:2:500, 2);
testdata(:, 1) = banana(501:2:1000, 1);
testdata(:, 2) = banana(501:2:1000, 2);
trainlabel = ones(size(traindata, 1), 1);
testlabel = -ones(size(testdata, 1), 1);
end
1 内容介绍
在现实世界中,万事万物都有着其特征,这样的特征或多或少、或重要或不重要。人们通过事物的特征可以确定其所属分类,但是当事物的特征都很多时,如果人们依靠传统的方法对事物进行分类就显得耗时耗力,并且分类的精确性不高。而分类作为一种预测模型,如果分类的精确性低或用时长,则这种预测将变得毫无价值。因此人们提出了各种分类模型来对事物进行预测,其中支持向量机和支持向量描述数据在对高维数据进行预测时有着一定的优势,并且根据不同的要求,对这两种算法的改进应用到了现实生活中的许多领域。 首先,本文研究了数据挖掘分类算法中的支持向量机的背景和理论,分析并总结了SVM各种改进方法的研究现状。
2 仿真代码
function x_range = grid_range(x, varargin)
%{
% DESCRIPTION
Compute the range of grid
x_range = grid_range(x)
x_range = grid_range(x, 'r', 0.5)
x_range = grid_range(x, 'n', 200)
x_range = grid_range(x, 'r', 0.5, 'n', 200)
INPUT
x Training inputs (N*1)
N: number of samples
r Radio of expansion (0<r<1)
n Number of grids
OUTPUT
x_range range of grid
Created on 18th October 2019, by Kepeng Qiu.
-------------------------------------------------------------%
%}
% Default Parameters setting
r = 0.5; % radio of expansion (0<r<1)
n = 2*size(x, 1); % number of grids
% Parameters setting
if ~rem(nargin, 2)
error('Parameters to rvm_train should be pairs')
end
numParameters = (nargin-1)/2;
if numParameters ~= 0
for i =1:numParameters
Parameters = varargin{(i-1)*2+1};
value = varargin{(i-1)*2+2};
switch Parameters
%
case 'r'
r = value;
%
case 'n'
n = value;
end
end
end
%
xlim_1 = min(x);
xlim_2 = max(x);
% min
if xlim_1<0
xlim_1 = xlim_1*(1+r);
else
xlim_1 = xlim_1*(1-r);
end
% max
if xlim_2<0
xlim_2 = xlim_2*(1-r);
else
xlim_2 = xlim_2*(1+r);
end
% range of grid
x_range = linspace(xlim_1, xlim_2, n);
end
function [traindata, testdata, trainlabel, testlabel] = prepareData
%{
% DESCRIPTION
Prepare the data for SVDD_WOA
[traindata, testdata, trainlabel, testlabel] = prepareData
OUTPUT
traindata Training data
testdata Testing data
trainlabel Training label
trainlabel Training label
Created on 18th October 2019, by Kepeng Qiu.
-------------------------------------------------------------%
%}
load .\data\banana.mat
traindata(:, 1) = banana(1:2:500, 1);
traindata(:, 2) = banana(1:2:500, 2);
testdata(:, 1) = banana(501:2:1000, 1);
testdata(:, 2) = banana(501:2:1000, 2);
trainlabel = ones(size(traindata, 1), 1);
testlabel = -ones(size(testdata, 1), 1);
end
function [rho, X1, X2] = decision_boundary(model, traindata)
%{
% DESCRIPTION
Computation of decision boundary
[rho, X1, X2] = decision_boundary(model, traindata)
INPUT
model SVDD model
N: number of samples
traindata Training data
OUTPUT
rho Bias term
X1, X2 Grid range
Created on 18th October 2019, by Kepeng Qiu.
-------------------------------------------------------------%
%}
% Compute the range of grid
x1_range = grid_range(traindata(:, 1));
x2_range = grid_range(traindata(:, 2));
% grid
[X1, X2] = meshgrid(x1_range, x2_range);
X_Grid = [X1(:), X2(:)];
% the grid label is only for the input of the function 'libsvmpredict'
grid_label = ones(size(X_Grid, 1), 1);
% Predict the label of each grid point
[~, ~, rho_0] = libsvmpredict(grid_label, X_Grid, model);
rho = reshape(rho_0, size(X1, 1), size(X1, 2));
end
function [traindata, testdata, trainlabel, testlabel] = prepareData
%{
% DESCRIPTION
Prepare the data for SVDD_WOA
[traindata, testdata, trainlabel, testlabel] = prepareData
OUTPUT
traindata Training data
testdata Testing data
trainlabel Training label
trainlabel Training label
Created on 18th October 2019, by Kepeng Qiu.
-------------------------------------------------------------%
%}
load .\data\banana.mat
traindata(:, 1) = banana(1:2:500, 1);
traindata(:, 2) = banana(1:2:500, 2);
testdata(:, 1) = banana(501:2:1000, 1);
testdata(:, 2) = banana(501:2:1000, 2);
trainlabel = ones(size(traindata, 1), 1);
testlabel = -ones(size(testdata, 1), 1);
end
3 运行结果
4 参考文献
[1]李传亮. 基于SVDD和参数辨识的模拟电路故障诊断方法研究[D]. 南京航空航天大学.
[2]肖托. 一种改进的支持向量数据描述算法[D]. 哈尔滨工程大学, 2013.
博主简介:擅长智能优化算法、神经网络预测、信号处理、元胞自动机、图像处理、路径规划、无人机等多种领域的Matlab仿真,相关matlab代码问题可私信交流。
部分理论引用网络文献,若有侵权联系博主删除。
3 运行结果
4 参考文献
[1]李传亮. 基于SVDD和参数辨识的模拟电路故障诊断方法研究[D]. 南京航空航天大学.
[2]肖托. 一种改进的支持向量数据描述算法[D]. 哈尔滨工程大学, 2013.
博主简介:擅长智能优化算法、神经网络预测、信号处理、元胞自动机、图像处理、路径规划、无人机等多种领域的Matlab仿真,相关matlab代码问题可私信交流。
部分理论引用网络文献,若有侵权联系博主删除。
边栏推荐
- iNFTnews | 元宇宙的潜力:一股推动社会进步的力量
- leetcode:139. 单词拆分
- 常用工具链和虚拟环境-TDMGCC
- [Arduino] Reborn Arduino Monk (2)----Arduino Language
- 【Objective-C语言中的@property增强】
- 【云原生】服务行业案例-不可预测的并发场景解决方案
- [Example构造方法增加notNull参数,默认false,允许值为null,值为null的时候不加入到条件中
- 数据中台建设(八):数据服务体系建设
- 网易数帆陈谔:云原生“牵手”低代码,加速企业数字化转型
- Jenkins2.328+sonarqube7.9 实现代码自动化检测
猜你喜欢
MySQL-多表查询
部门之间,互不信任正常吗?(你是否遇到过)
MySQL-Explain详解
【Flink】使用arthas在线诊断flink的那些事
rancher集成ldap,实现统一账号登录
问题记录:jenkins构建时报错The goal you specified requires a project to execute but there is no POM in...
Linux定时任务脚本执行时mysqldump备份异常的问题
征集 |《新程序员》专访“Apache之父”Brian Behlendorf,你最想问什么?
leetcode:152. 乘积最大子数组
initramfs详解-----初识initramfs
随机推荐
ClickHouse常用函数速查大全
在排列中求lcs
新库上线 | CnOpenDataA股上市公司董监高信息数据
numpy PIL tensor之间的相互转换
Incorrect datetime value: '2022-01-01' for function str_to_date
ssh(sshd)安全配置
钻石基础知识介绍
YYGH-BUG-06
一次偶然的钓鱼文件分析
自定义RunTimeException工具类
VS中使用BugTrap定位程序崩溃点
mysql-installer安装教程(详细图文)
pytorch 中 permute()函数的用法
PHICOMM(斐讯)N1盒子 - Armbian5.77(Debian 9)基本配置
Jmeter TCP/UDP测试
[QNX Hypervisor 2.2用户手册]10 虚拟设备参考
力扣第二周错题集
.NET in-depth analysis of the LINQ framework (four: IQueryable, IQueryProvider interface details)
[Static type and dynamic type compile check and run check in Objective-C]
[@property enhancement in Objective-C language]