Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Estimate a One-Class SVM model
- trainRows <- c(1:30, 51:80, 101:130)
- testRows = !(1:150 %in% trainRows)
- trainIris <- iris[trainRows,]
- testIris <- iris[testRows,]
- trainIris$id <- seq.int(nrow(trainIris))
- svmModel <- rxOneClassSvm(
- formula = ~Sepal.Length + Sepal.Width + Petal.Length + Petal.Width,
- data = trainIris)
- # Add additional non-iris data to the test data set
- testIris$isIris <- 1
- notIris <- data.frame(
- Sepal.Length = c(2.5, 2.6),
- Sepal.Width = c(.75, .9),
- Petal.Length = c(2.5, 2.5),
- Petal.Width = c(.8, .7),
- Species = c("not iris", "not iris"),
- isIris = 0)
- testIris <- rbind(testIris, notIris)
- testIris$id <- seq.int(nrow(testIris))
- scoreDF <- rxPredict(svmModel,
- data = testIris, extraVarsToWrite = c("isIris", "id"))
- # Look at the last few observations
- tail(scoreDF)
- # Look at average scores conditioned by 'isIris'
- rxCube(Score ~ F(isIris), data = scoreDF)
- rxLinePlot(Score~id, type = c("p"), data = scoreDF,
- title = "Scores from rxOneClassSvm",
- symbolColor = ifelse(scoreDF$isIris == 0, "red", "blue"))
Add Comment
Please, Sign In to add comment