開始使用免費開始

使用 `tune.svm()`

這個練習會帶你實作使用 tune.svm() 函式。你會用它來為基於本章先前建立之徑向可分資料集的 SVM 模型,找出 costgammacoef0 的最佳參數值。訓練資料在資料框 trainset,測試資料在 testset,而且已為你預先載入 e1071 套件。請記得類別變數 y 位於 trainsettestset 的第 3 欄。

另外回想影片中,Kailash 使用 cost=10^(1:3),讓 cost 參數以 10 的倍數,從 10=10^11000=10^3

本練習屬於課程

R 的支援向量機

檢視課程

練習說明

  • 請將參數搜尋範圍設為:
    • cost:從 0.1(10^(-1))到 100(10^2),以 10 的倍數遞增。
    • gammacoef0:可用值為 0.1、1、10。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

#tune model
tune_out <- 
    tune.svm(x = trainset[, -3], y = trainset[, 3], 
             type = "C-classification", 
             kernel = "polynomial", degree = 2, cost = 10^(___:___), 
             gamma = c(___, ___, ___), coef0 = c(0.1, 1, 10))

#list optimal values
tune_out$best.parameters$___
tune_out$best.parameters$___
tune_out$best.parameters$___
編輯並執行程式碼