MulaiMulai sekarang secara gratis

Using `tune.svm()`

This exercise will give you hands-on practice with using the tune.svm() function. You will use it to obtain the optimal values for the cost, gamma, and coef0 parameters for an SVM model based on the radially separable dataset you created earlier in this chapter. The training data is available in the dataframe trainset, the test data in testset, and the e1071 library has been preloaded for you. Remember that the class variable y is stored in the third column of the trainset and testset.

Also recall that in the video, Kailash used cost=10^(1:3) to get a range of the cost parameter from 10=10^1 to 1000=10^3 in multiples of 10.

Latihan ini adalah bagian dari kursus

Support Vector Machines in R

Lihat Kursus

Petunjuk latihan

  • Set parameter search ranges as follows:
    • cost - from 0.1 (10^(-1)) to 100 (10^2) in multiples of 10.
    • gamma and coef0 - one of the following values: 0.1, 1 and 10.

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

#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$___
Edit dan Jalankan Kode