Svm
如何選擇要使用的 SVM 內核?
如果沒有提前測試,我無法確定我應該在非線性 SVM 中使用什麼內核。我想知道是否有其他方法可以在沒有測試的情況下確定最佳內核?它與數據有什麼關係?
使用幾個不同的內核進行分析。確保你交叉驗證。選擇在交叉驗證期間表現最佳的內核並將其擬合到您的整個數據集。
/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)