Different number of support vectors & decision values in R (using svm from "e1071") and matlab (fitcsvm) for one class classification

2 次查看(过去 30 天)
I am trying to run svm both on R and matlab.
R code:
data= df[, 1:2]
head(data)
sum(is.na(data))
data_bislery= as.numeric(data$PH, data$TDS)
mdl= svm(data_bislery,gamma = 1,nu = 0.5)
mdl$decision.values
mdl$SV
summary(mdl)
matlab code:
data= d_new(:,1:2)
y= ones(552,1)
model= fitcsvm(D,y,"KernelScale",1, Nu=0.5, KernelFunction="rbf")
[~,s]= predict(model, D)
Both the codes are giving different results. Even the data used for both the code is same but they are giving very different results.
Number of support vectors for R is 279 while in matlab are 286. R have -ve and +ve distance values while matlab has only positive decision values.
Please help me the theory behind both the softwares so that i can get same results when using same data on both the softwares.

采纳的回答

Raj
Raj 2024-3-22
As per my understanding, even though same algorithm is being implemented, in this case SVM, there can be differences in implemenation details that might lead to slightly different results. Implementation details such as optimization algorithm, numerical precision, or how edge cases are handled can be different in both 'R' and 'MATLAB'.
In theory, if you use the exact same data, preprocessing steps, SVM algorithm (including the kernel function), and all hyperparameters (like C, gamma for the RBF kernel, and nu ), you might expect to get very similar, if not identical, outputs from SVM in both R and MATLAB.
Hope this helps!

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Operating on Diagonal Matrices 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by