Guest User

Untitled

a guest
May 23rd, 2017
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. # Estimate a One-Class SVM model
  2. trainRows <- c(1:30, 51:80, 101:130)
  3. testRows = !(1:150 %in% trainRows)
  4. trainIris <- iris[trainRows,]
  5. testIris <- iris[testRows,]
  6.  
  7. trainIris$id <- seq.int(nrow(trainIris))
  8. svmModel <- rxOneClassSvm(
  9. formula = ~Sepal.Length + Sepal.Width + Petal.Length + Petal.Width,
  10. data = trainIris)
  11.  
  12. # Add additional non-iris data to the test data set
  13. testIris$isIris <- 1
  14. notIris <- data.frame(
  15. Sepal.Length = c(2.5, 2.6),
  16. Sepal.Width = c(.75, .9),
  17. Petal.Length = c(2.5, 2.5),
  18. Petal.Width = c(.8, .7),
  19. Species = c("not iris", "not iris"),
  20. isIris = 0)
  21. testIris <- rbind(testIris, notIris)
  22.  
  23. testIris$id <- seq.int(nrow(testIris))
  24. scoreDF <- rxPredict(svmModel,
  25. data = testIris, extraVarsToWrite = c("isIris", "id"))
  26.  
  27. # Look at the last few observations
  28. tail(scoreDF)
  29. # Look at average scores conditioned by 'isIris'
  30. rxCube(Score ~ F(isIris), data = scoreDF)
  31.  
  32. rxLinePlot(Score~id, type = c("p"), data = scoreDF,
  33. title = "Scores from rxOneClassSvm",
  34. symbolColor = ifelse(scoreDF$isIris == 0, "red", "blue"))
Add Comment
Please, Sign In to add comment