1 / 4

SVM en R, el paquete e1071

SVM en R, el paquete e1071. > names(tinto) [1] "fixed.acidity" "volatile.acidity" [3] "citric.acid" "residual.sugar" [5] "chlorides" "free.sulfur.dioxide" [7] "total.sulfur.dioxide" "density " [9] "pH" "sulphates"

reia
Télécharger la présentation

SVM en R, el paquete e1071

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. SVM en R, el paquete e1071 > names(tinto) [1] "fixed.acidity" "volatile.acidity" [3] "citric.acid" "residual.sugar" [5] "chlorides" "free.sulfur.dioxide" [7] "total.sulfur.dioxide" "density" [9] "pH" "sulphates" [11] "alcohol" "quality" Trabajamos con el dataset de vinos tintos verdes portugueses > unique(tinto$quality) [1] 5 6 7 4 8 3 > qualcod <- ifelse(tinto$quality %in% c(7,8), 1, -1) > table(qualcod) qualcod -1 1 1382 217 Separamos en dos clases los vinos de categoría 7 y 8 del resto

  2. SVM en R, el paquete e1071 • > ind <- 1:nrow(tinto) • > testind <-sample(ind, trunc(length(ind)/3)) • > tinto <- data.frame(tinto, qualcod) • > testset <- tinto[testind, -12] • > trainset <- tinto[-testind, -12] • > tinto.tunesvm <- tune.svm(as.factor(qualcod)~., • data=trainset, gamma=2^(-3:3), cost=2^(0:4)) • > summary(tinto.tunesvm) • Parameter tuning of ‘svm’: • - sampling method: 10-fold cross validation • - best parameters: gamma cost 1 2 • - best performance: 0.0956974 • Detailed performance results: • gamma cost error dispersion • 1 0.125 1 0.11728090 0.01498582 • 2 0.250 1 0.11447716 0.02505541 • ...

  3. SVM en R, el paquete e1071 Con la función tune.svm se puede recorrer una grilla de valores de los parámetros y obtener la mejor combinación. En el caso anterior: gamma =1 C=2 > plot(tinto.tunesvm) > tinto.svm <- tinto.tunesvm$best.model > tinto.svm.pred <- predict(tinto.svm, testset[,-12]) > table(predicho=tinto.svm.pred, verdadero=testset[,12]) verdadero predicho -1 1 -1 451 50 1 8 24 > (8+50)/(nrow(testset)) [1] 0.1088180

  4. Clasificando por knn: > tinto.knn <- knn(trainset[, -12], testset[, -12], trainset$qualcod, k=15) > table(predicho=tinto.knn, verdadero=testset[,12]) > (70+2)/nrow(testset) verdadero predicho -1 1 -1 457 70 1 2 4 > (70+2)/(nrow(testset)) [1] 0.1350844

More Related