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

SVM Gaussian Kernel 支持向量机
MATLAB代码

公式
K g a u s s i a n ( x ( i ) , x ( j ) ) = exp ⁡ ( − ∥ x ( i ) − x ( j ) ∥ 2 2 σ 2 ) = exp ⁡ ( − ∑ k = 1 n ( x k ( i ) − x k ( j ) ) 2 2 σ 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
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值