How to write gaussian kernel function for fitcsvm?

6 ビュー (過去 30 日間)
shawqi farea
shawqi farea 2020 年 3 月 23 日
編集済み: shawqi farea 2020 年 3 月 23 日
I tried to write the gaussian (RBF) kernel function for Support Vector Machine functions (like fitcecoc or fitcsvm) and my code was:
function G = myGaussianFunc(U,V)
global sigma
[m p] = size(U);
[n, ~] = size(V);
UX = repelem(U,n,1);
VX = repmat(V,m,1);
T = (UX - VX).^2*ones(p,1);
G = exp(-reshape(T,m,n)/(2*sigma^2));
end
I made sigma (kernel scale) global so I can optimize it using some algorithm. Is my code accurate or do I have some mistakes in it? (By the way, I avoided the for loop and tried to vectorize the code to speed it up)

回答 (0 件)

カテゴリ

Help Center および File ExchangeSupport Vector Machine Classification についてさらに検索

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by