如果没有提前测试,我无法确定我应该在非线性 SVM 中使用什么内核。我想知道是否有其他方法可以在没有测试的情况下确定最佳内核?它与数据有什么关系?
如何选择要使用的 SVM 内核?
机器算法验证
支持向量机
非线性回归
内核技巧
2022-03-14 14:50:23
1个回答
使用几个不同的内核进行分析。确保你交叉验证。选择在交叉验证期间表现最佳的内核并将其拟合到您的整个数据集。
/edit:这是 R 中的一些示例代码,用于分类 SVM:
#Use a support vector machine to predict iris species
library(caret)
library(caTools)
#Choose x and y
x <- iris[,c("Sepal.Length","Sepal.Width","Petal.Length","Petal.Width")]
y <- iris$Species
#Pre-Compute CV folds so we can use the same ones for all models
CV_Folds <- createMultiFolds(y, k = 10, times = 5)
#Fit a Linear SVM
L_model <- train(x,y,method="svmLinear",tuneLength=5,
trControl=trainControl(method='repeatedCV',index=CV_Folds))
#Fit a Poly SVM
P_model <- train(x,y,method="svmPoly",tuneLength=5,
trControl=trainControl(method='repeatedCV',index=CV_Folds))
#Fit a Radial SVM
R_model <- train(x,y,method="svmRadial",tuneLength=5,
trControl=trainControl(method='repeatedCV',index=CV_Folds))
#Compare 3 models:
resamps <- resamples(list(Linear = L_model, Poly = P_model, Radial = R_model))
summary(resamps)
bwplot(resamps, metric = "Accuracy")
densityplot(resamps, metric = "Accuracy")
#Test a model's predictive accuracy Using Area under the ROC curve
#Ideally, this should be done with a SEPERATE test set
pSpecies <- predict(L_model,x,type='prob')
colAUC(pSpecies,y,plot=TRUE)