One class classification using fitcsvm
5 ビュー (過去 30 日間)
古いコメントを表示
Classifier<- svm(PhaseI_Data,type='one-classification',kernel = "radial",
nu= nu,gamma= gamma, scale = F)
Above written code is from R. where nu is penalty factor, gamma is kernel bandwidth in radial kernel.
Can someone help me to write equivalent code in matlab.
I have tried multiple times but it is giving different results in both.
0 件のコメント
回答 (1 件)
Hitesh
2025 年 6 月 2 日
編集済み: Hitesh
2025 年 6 月 2 日
Hi Nainsi,
MATLAB uses the "fitcsvm function". However, "fitcsvm"does not support one-class classification directly. You need to use the "fitcsvm" with 'OutlierFraction', which is equivalent to 1 - nu in R.
Kindly refer to the following code as example to implement "One class classification using fitcsvm".
% Assume PhaseI_Data is an n-by-d matrix (observations x features)
% and already normalized/scaled similarly to how it was used in R.
% Example dummy data: 100 points in 2D
PhaseI_Data = randn(100, 2); % Normally distributed data
% Convert R gamma to MATLAB's kernel scale:
% R: k(x, y) = exp(-gamma * ||x - y||^2)
% MATLAB: uses 'KernelScale', which is sigma such that
% k(x, y) = exp(-||x - y||^2 / (2*sigma^2))
gamma = 0.1; % or whatever value you used in R
sigma = sqrt(1 / (2 * gamma));
% MATLAB One-Class SVM equivalent:
SVMModel = fitcsvm(PhaseI_Data, ones(size(PhaseI_Data,1),1), ...
'KernelFunction', 'rbf', ...
'KernelScale', sigma, ...
'OutlierFraction', 1 - 0.1, ...
'Standardize', false);
For more information regarding "fitcsvm", kindly refer to the following MATLAB documentation:
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Get Started with MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!