[Support Vector Machine (SVM)]: Gaussian Kernel Matlab Implementation

本文深入解析了支持向量机(SVM)中高斯核函数的原理及MATLAB实现代码,展示了如何通过高斯核函数计算样本之间的相似度,适用于解决非线性分类问题。

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

SVM Gaussian Kernel 支持向量机
MATLAB代码

公式
Kgaussian(x(i),x(j))=exp⁡(−∥x(i)−x(j)∥22σ2)=exp⁡(−∑k=1n(xk(i)−xk(j))22σ2)K_{gaussian}(x^{(i)},x^{(j)}) =\exp\left(-\frac{\left\| x^{(i)}-x^{(j)}\right\|^2}{2\sigma^2}\right) =\exp\left(-\frac{\sum_{k=1}^n{(x_k^{(i)}-x_k^{(j)})^2}}{2\sigma^2}\right)Kgaussian(x(i),x(j))=exp(2σ2x(i)x(j)2)=exp(2σ2k=1n(xk(i)xk(j))2)

function sim = gaussianKernel(x1, x2, sigma)
%RBFKERNEL returns a radial basis function kernel between x1 and x2
%   sim = gaussianKernel(x1, x2) returns a gaussian kernel between x1 and x2
%   and returns the value in sim

% Ensure that x1 and x2 are column vectors x1 = [1 2 1]; x2 = [0 4 -1]; 
x1 = x1(:); x2 = x2(:);

% You need to return the following variables correctly.
sim = 0;

% ===========================================
% Instructions: Fill in this function to return the similarity between x1
%               and x2 computed using a Gaussian kernel with bandwidth
%               sigma

% Simularity function
% 方法一
sim = exp(-((x1-x2)' * (x1-x2)) / (2 * sigma^2));
% 方法二
sim = exp(-sum((x1-x2).^2)/(2*sigma^2));

end
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值